Restkit授权标题消失

时间:2015-06-20 20:13:34

标签: ios swift afnetworking restkit

我已经到处搜索过,这个应该是微不足道的问题比我想要的时间更长,因此我会向你寻求帮助。

我使用cocoapods使用swift和集成的restkit。

尽管你可以看到屏幕截图/日志,但标题很好,但是传出的http数据包不一致。

的AppDelegate:

RKlcl_configure_by_name("RestKit/Network", RKlcl_vTrace.value);
RKlcl_configure_by_name("RestKit/ObjectMapping", RKlcl_vTrace.value);

ObjectManagerCode:

let objectManager: RKObjectManager = RKObjectManager(baseURL: NSURL(string: Endpoints.BaseUrl.toString()))
objectManager.requestSerializationMIMEType = RKMIMETypeJSON;

let username = "TestUser"
let password = "password"

objectManager.HTTPClient.setAuthorizationHeaderWithUsername(username, password: password)
objectManager.HTTPClient.setDefaultHeader("whatIWantForChristmas", value: "You")
objectManager.HTTPClient.allowsInvalidSSLCertificate = true

请求:

var requestUrl = cds.objectManager!.requestWithObject(
        nil,
        method: RKRequestMethod.GET,
        path: endpoint.path,
        parameters: endpoint.parameters())



cds.objectManager!.getObjectsAtPath(
        endpoint.path,
        parameters: endpoint.parameters(),
        success:
        {
            (RKObjectRequestOperation, RKMappingResult) -> Void in

            println(RKObjectRequestOperation.description)
            Logger.Info("Success");
        },
        failure: {
            (RKObjectRequestOperation, error) -> Void in

            Logger.Error("Error: \(error.description)")
            println(RKObjectRequestOperation.HTTPRequestOperation.description)

        })

日志:

T restkit.network:RKObjectRequestOperation.m:178 GET 'http://website/api?format=json':

request.headers={
    Accept = "application/json";
    "Accept-Language" = "en;q=1, fr;q=0.9, de;q=0.8, zh-Hans;q=0.7, zh-Hant;q=0.6, ja;q=0.5";
    Authorization = "Basic VGVzdFVzZXI6cGFzc3dvcmQ=";
    "User-Agent" = "malaria-ios/1 (iPhone Simulator; iOS 8.3; Scale/2.00)";
    whatIWantForChristmas = You;
}

...

E restkit.network:RKObjectRequestOperation.m:576 Object request
failed:Underlying HTTP request operation failed with error: 
Error Domain=org.restkit.RestKit.ErrorDomain Code=-1011 "Expected status code in (200), got 403" 
UserInfo=0x7ff54ae4f690 {NSLocalizedRecoverySuggestion={"detail":"Authentication credentials were not provided."}

我发现了什么: 我可以在标题中发送任何内容,只要它不是"授权",如果我改为"授权2",好的。标题" WhatIWantForChristmas"也在那里。尽管存在于日志中,授权仍然没有!似乎底层软件过滤了。

出于偏执,我试图关闭防火墙,清理项目,重置iOS模拟器和虚拟现实。我用来查看HTTP数据包的应用程序是Charles。

我做错了什么?

屏幕截图的网址:http://s7.postimg.org/pfwn7kyq2/Screen_Shot_2015_06_20_at_21.jpg

0 个答案:

没有答案