0

I am currently trying to migrate my company's app over to Swift from ObjC and I am running into some issues with POST requests using the new NSURLSession API (specifically dataTaskWithRequest:completionHandler:). I'm simply trying to make a POST with some URL encoded params (e.g., somekey=someval&anotherkey=anotherval) as my body. The request fails with this error when I try to send a body with the POST.

NSUnderlyingError=0x7ff20bd28b90 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1005.)"

Strangely, when I do not send a body, the request succeeds. This doesn't cut it for my use case as I need to send in a body with my request. Headers don't seem to matter either.

I've found a couple of GitHub/SO threads on this general subject, namely this one, but the difference being I am only making one request and I get this error.

My first thought obviously is that something is wrong in my body, but even URL encoding it doesn't seem to fix the issue.

This is my set up:

  • Xcode 6.1 6A1052d
  • OS X 10.10 14A389

I am trying this in a Cocoa Touch Framework project and I am encountering this error using XCTest (trying to write unit tests to start out).

Any help or guidance would be greatly appreciated. Thanks!

Stefan Arambasich
  • 2,231
  • 2
  • 19
  • 24
  • See [this post](http://stackoverflow.com/questions/25372318/error-domain-nsurlerrordomain-code-1005-the-network-connection-was-lost) on error -1005 in the iOS 8 simulator. – nickgraef Nov 03 '14 at 23:52
  • While -1005 in that case is the same, the reported error message is different. Restarting both Xcode and the simulator did not alleviate the issue. – Stefan Arambasich Nov 04 '14 at 02:13

1 Answers1

1

Turns out I was not setting the HTTPMethod to "POST"... Kinda wish the error was more specific about that.

Stefan Arambasich
  • 2,231
  • 2
  • 19
  • 24