Parrots
Parrots

Reputation: 26902

Connection reset by peer with iPhone NSURLConnection

I'm trying to connect to a C# HTTP server with an iPhone app. Pretty simple code so far:

    NSData *requestData = [ NSData dataWithBytes: [ requestMessage UTF8String ] length: [ requestMessage length ] ];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:infoURL]];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
    [request setHTTPMethod: @"POST"];
    [request setHTTPBody: requestData];
    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

The server gets the request, sends a response, and then terminates the connection. The iPhone reports connection reset by peer.

To be able to hit the server in Firefox on my desktop I need to go into it's advanced preffs and disabled keep-alive. The reason, I assume, is because I'm terminating the connection right after I sent the response. I do so because I don't want to reuse connections later.

Anyway to disable keep-alive when using NSURLConnection on the iPhone, or any suggestions on modifying my .Net code?

Upvotes: 0

Views: 1655

Answers (2)

Parrots
Parrots

Reputation: 26902

This actually seemed to be a bug in the beta of the iOS version I was using. A future update and the same code worked just fine.

Upvotes: 0

Jordan
Jordan

Reputation: 21760

Why not just add Connection: Close to the HTTP/1.1 Request?

Upvotes: 1

Related Questions