Here's where I am so far with NSURLSessionUploadTask
:
- iOS application starts an
NSURLSessionUploadTask
using POST - server receives HTTP POST request
- server reads content of the request so data is uploaded
- server sends HTTP response to iOS consisting of the following:
HTTP/1.1 200 OK Server: BaseHTTP/0.3 Python/2.7.10 Date: Fri, 30 Oct 2015 16:15:21 GMT Content-Type: text/html Content-Length: 96 <html><head><title>POST RESPONSE</title></head><body><p>The file was uploaded.</p></body></html>
- iOS application receives response and
NSLogs
the response viaNSURLSessionTaskDelegate -> URLSession:task:didCompleteWithError:
<NSHTTPURLResponse: 0x15d95110> { URL: http://10.157.239.129:42000/ } { status code: 200, headers { "Content-Length" = 96; "Content-Type" = "text/html"; Date = "Fri, 30 Oct 2015 16:15:21 GMT"; Server = "BaseHTTP/0.3 Python/2.7.10"; } }
- however, when I try to
NSLog
the response content when the methodNSURLSessionTaskDelegate: -> URLSession:dataTask:didReceiveData:
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data { // Called when data task has received some data (not applicable for straight upload?) if (data != NULL) { NSLog(@"%s: %@", __PRETTY_FUNCTION__,[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); } else { NSLog(@"%s: but no actual data received.", __PRETTY_FUNCTION__); } // If we are not in the "active" or foreground then log some background information to the console if (UIApplication.sharedApplication.applicationState != UIApplicationStateActive) { [BackgroundTimeRemainingUtility NSLog]; } }
- is called I get this for output:
2015-10-30 12:15:22.648 NSURLSessionUploadTaskExample[215:7286] -[ViewController URLSession:dataTask:didReceiveData:]: (null)
- what is odd about this is that the response should not have triggered the if statement block if the data is null!
- I also have evidence that the response data WAS sent to the iOS application via Wireshark. Here's a packet capture of the HTTP response from the server:
Can anyone tell me why iOS appears to be losing the content in the HTTP response?