iOS Can't perform HTTP GET request -Error Domain=NSURLErrorDomain Code=-1012

后端 未结 4 910
长发绾君心
长发绾君心 2020-12-16 14:35

I am trying to perform a HTTP Get request, but I keep on getting Error Domain=NSURLErrorDomain Code=-1012 error. MY code is :

@try {
    NSString *url = [[N         


        
相关标签:
4条回答
  • 2020-12-16 15:10

    This error is NSURLErrorUserCancelledAuthentication

    Returned when an asynchronous request for authentication is cancelled by the user. This is typically incurred by clicking a “Cancel” button in a username/password dialog, rather than the user making an attempt to authenticate.

    It means you need authentication to access the resource which you are trying to access w/o signing your request properly (wrong agentSecret or API_ID or API_SECRET)

    0 讨论(0)
  • 2020-12-16 15:12

    You may get this error while hitting a HTTPS (not HTTP) URL with a bad/expired certificate with AFNetworking. (Chrome shows the "Your connection is not private" message when hitting the URL).

    0 讨论(0)
  • 2020-12-16 15:22

    For my case i just set Yes for following flag of afnetworking http client. allowsInvalidSSLCertificate = YES, it starts working for https get request.

    0 讨论(0)
  • 2020-12-16 15:28

    If it helps anyone, you will get this error whenever a server sends back a 401 (unauthorized) status code.

    0 讨论(0)
提交回复
热议问题