简体   繁体   中英

domain NSURLErrorDomain code 4294966292

My request crashes "domain NSURLErrorDomain code 4294966292".

let request = NSMutableURLRequest(URL: NSURL(string: IPPost)!)
let session = NSURLSession.sharedSession()

request.HTTPMethod = "POST"

request.HTTPBody = "text".dataUsingEncoding(NSUTF8StringEncoding);

request.addValue("text/plain; charset=UTF-8", forHTTPHeaderField: "Content-Type")

let task = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in

    let strData = NSString(data: data!, encoding: NSUTF8StringEncoding)

The file "info.plist" I added "NSAllowsArbitraryLoads = true"

Prompt, please, what am I doing wrong?

4294966292 is the Unsigned Int32 version of -1004. You can convert it via: Int32(bitPattern: 4294966292) for your reference.

Error code -1004 is for cfurlErrorCannotConnectToHost, see the docs here: https://developer.apple.com/reference/cfnetwork/cfnetworkerrors/1417006-cfurlerrorcannotconnecttohost

Likely this means there is something wrong with the server you are trying to connect to (whatever the URL of IPPost is). I have hit this error before when my server was down and had forgot to turn it back on. It's also possible you have malformed the URL so it's trying to access a site that doesn't exist.

I would try printing out the URL and manually double checking it with a browser or a curl command first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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