错误域= com.alamofire.error.serialization.response代码= -1011“请求失败:禁止(403)

时间:2016-12-14 14:36:36

标签: ios swift afnetworking afnetworking-3

我正在使用AFNetworking 3.1.0发出http请求。 在我提出请求后,它显示在下面。我提出请求的代码在底部。如果没有ssl VPN,你可以看到下面的网址。

  

错误Domain = com.alamofire.error.serialization.response Code = -1011   “请求失败:禁止(403)”   UserInfo = {com.alamofire.serialization.response.error.response = {URL:   https://223.71.215.70/web/1/http/0/10.100.5.105:6666/entry} {状态   代码:403,headers {       连接=“保持活力”;       “内容长度”= 238;       “Content-Type”=“text / html; charset = iso-8859-1”;       日期=“2016年12月14日星期三格林尼治标准时间14:27:48”;       “Keep-Alive”=“timeout = 15,max = 100”;       “X-Frame-Options”= SAMEORIGIN; ,NSErrorFailingURLKey = https://223.71.215.70/web/1/http/0/10.100.5.105:6666/entry,   NSLocalizedDescription =请求失败:禁止(403),   com.alamofire.serialization.response.error.data =< 3c21444f 43545950   45204854 4d4c2050 55424c49 4320222d 2f2f4945 54462f2f 44544420   48544d4c 20322e30 2f2f454e 223e0a3c 68746d6c 3e3c6865 61643e0a   3c746974 6c653e34 30332046 6f726269 6464656e 3c2f7469 746c653e   0a3c2f68 6561643e 3c626f64 793e0a3c 68313e46 6f726269 6464656e   3c2f6831 3e0a3c70 3e596f75 20646f6e 27742068 61766520 7065726d   69737369 6f6e2074 6f206163 63657373 202f7765 622f312f 68747470   2f302f31 302e3130 302e352e 3130353a 36363636 2f656e74 72790a6f   6e207468 69732073 65727665 722e3c2f 703e0a3c 2f626f64 793e3c2f   68746d6c 3e0a>}请求失败:禁止(403)

let config = URLSessionConfiguration.default
config.timeoutIntervalForRequest = 30
let manager = AFHTTPSessionManager(sessionConfiguration: config)
manager.requestSerializer = AFHTTPRequestSerializer() // AFJSONRequestSerializer(writingOptions: .prettyPrinted)
manager.responseSerializer = AFHTTPResponseSerializer() // AFJSONResponseSerializer(readingOptions: .mutableContainers)
//      manager.responseSerializer.acceptableContentTypes = ["text/html"]
manager.responseSerializer.acceptableContentTypes = ["application/json", "text/json", "text/JavaScript", "text/html", "text/plain"]
let policy = AFSecurityPolicy(pinningMode: .none)
policy.allowInvalidCertificates = true
policy.validatesDomainName = false
manager.securityPolicy = policy

manager.post(url, parameters: para, progress: nil, success: { (task:URLSessionDataTask, a:Any?) in
            print(123)
        }) { (task: URLSessionDataTask?, error: Error) in
//          print(task?.description)
            print(error)
            print(error.localizedDescription)
        }

1 个答案:

答案 0 :(得分:0)

我发现如果我的手机时钟不同步......也许检查一下你的手机是否设置在正确的时间“自动区”,看看是否有效......

参考网址:https://community.fitbit.com/t5/Charge-HR/Can-t-set-up-error-Forbidden-403/td-p/1053680