NSURLErrorDomain Code=-1001 error when a http post request is sent

后端 未结 5 2108
慢半拍i
慢半拍i 2021-01-17 14:48

I am using the following code to post an image to my server.

@IBAction func postButtonPressed(sender: UIButton) {
    let task = NSURLSession.sharedSession(         


        
相关标签:
5条回答
  • 2021-01-17 15:13

    I fixed using headers with application/json and sending on the request:

    let headers: HTTPHeaders = [
            .accept("application/json")
    ]
    AF.request(url, method: .post, parameters: score, encoder: JSONParameterEncoder.default, headers: headers)
    
    0 讨论(0)
  • 2021-01-17 15:25

    Well, in my case simply increasing the timeout of request solved the problem.

    0 讨论(0)
  • 2021-01-17 15:29

    Apparently my post request was getting a timeout error since I was sending an image that the server would find too large. I scaled down the images in order to make my images acceptable by the server.

    As this post suggests, NSURLErrorDomain Code=-1001 error might be caused by many things including;

    • Server response time limit
    • Server rules about the incoming data
    • Authentication problems

    Hope that helps to other people

    0 讨论(0)
  • 2021-01-17 15:31

    In my case issue was in 3rd party library - FirebasePerformance. Bug report URL: https://github.com/firebase/firebase-ios-sdk/issues/486

    0 讨论(0)
  • 2021-01-17 15:35

    It is late to reply but I recently face the error while running the new application assigned to me. The application is one of them whose URL Domains are blocked by the system administrator of my company.
    I ask them to allow me the URL access after which the response came and the application run perfectly.
    This may be not the actual solution for everyone but some of the developers may have the restricted environment can get help by this.

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