简体   繁体   English

NSURLErrorDomain代码= -1012

[英]NSURLErrorDomain Code=-1012

I keep getting this error when I make a request to an api. 向api发出请求时,我总是收到此错误。 The api requires authentication and for this I add valid OAuth token to the header of the request. api需要身份验证,为此,我将有效的OAuth令牌添加到请求的标头中。 When I do that I receive a 200 response so all is good. 当我这样做时,我收到200条回复,所以一切都很好。

But I want to test my code to handle a 401 response code. 但是我想测试我的代码以处理401响应代码。 To do this I add a invalid OAuth token to the request. 为此,我向请求添加了无效的OAuth令牌。 I was expecting the server to just send a 401 response code but instead I got an error from my callback. 我期望服务器仅发送401响应代码,但从回调中收到错误。 The error is NSURLErrorDomain Code=-1012, and after looking online it turns out this is a authentication error. 错误是NSURLErrorDomain Code = -1012,并且在联机查看后,原来是身份验证错误。

I was expecting the server to just send a 401 back? 我期望服务器只发送回401吗? Instead I'm getting a error in my callback. 相反,我在回调中遇到错误。 Is there something wrong with my server or my request? 我的服务器或请求有问题吗?

Thanks for the replies... 感谢您的回覆...

我认为也许您需要与委托建立NSURLConnection才能以所需的方式处理此问题。

I was using charles proxy and that was the reason I saw this error. 我正在使用Charles代理,这就是我看到此错误的原因。 When I stopped using the proxy it worked like a charm. 当我停止使用代理时,它就像一种魅力。

Ps I've not tested this with NSURLSession but if anyone is curious just add a comment! 附言:我还没有使用NSURLSession对此进行过测试,但是如果有人好奇,请添加评论! :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM