Hi everyone,
I've written a very simple HTTP server in Java which works very fine. There's only one small thing which I am not being able to figure out and that is when I send a HTTP request from my iPhone app, the HTTP server is able to detect the request and is able to respond to it and and then my iPhone app is able to display that response BUT the HTTP server is not able to see any data that is sent from the iPhone app. Below is code that does the HTTP request. Is there anything I'm doing wrong while setting the data into the HTTP request's body?
// Creating HTTP request
NSURL *oRequestUrl = [NSURL URLWithString😠"url"];
NSMutableURLRequest *oRequest = [[[NSMutableURLRequest alloc] init] autorelease];
[oRequest setURL😮RequestUrl];
[oRequest setHTTPMethod😠"POST"];
[oRequest addValue😠"text/plain" forHTTPHeaderField😠"Content-Type"];
NSMutableData *oHttpBody = [NSMutableData data];
[oHttpBody appendData:[@"iPhone" dataUsingEncoding:NSUTF8StringEncoding]];
[oRequest setHTTPBody😮HttpBody];
NSString *oHttpBodyLengthString = [[NSString alloc] initWithFormat😠"%d", [oHttpBody length]];
[oRequest addValue😮HttpBodyLengthString forHTTPHeaderField😠"Content-Length"];
NSError *oError = [[NSError alloc] init];
NSHTTPURLResponse *oResponseCode = nil;
NSData *oResponseData = [NSURLConnection
sendSynchronousRequest😮Request
returningResponse😮ResponseCode
error😮Error];
NSString *strResult = [[NSString alloc]
initWithData😮ResponseData
encoding:NSUTF8StringEncoding];
// Setting label value to HTTP server's response
[label setText:strResult];
I've written a very simple HTTP server in Java which works very fine. There's only one small thing which I am not being able to figure out and that is when I send a HTTP request from my iPhone app, the HTTP server is able to detect the request and is able to respond to it and and then my iPhone app is able to display that response BUT the HTTP server is not able to see any data that is sent from the iPhone app. Below is code that does the HTTP request. Is there anything I'm doing wrong while setting the data into the HTTP request's body?
// Creating HTTP request
NSURL *oRequestUrl = [NSURL URLWithString😠"url"];
NSMutableURLRequest *oRequest = [[[NSMutableURLRequest alloc] init] autorelease];
[oRequest setURL😮RequestUrl];
[oRequest setHTTPMethod😠"POST"];
[oRequest addValue😠"text/plain" forHTTPHeaderField😠"Content-Type"];
NSMutableData *oHttpBody = [NSMutableData data];
[oHttpBody appendData:[@"iPhone" dataUsingEncoding:NSUTF8StringEncoding]];
[oRequest setHTTPBody😮HttpBody];
NSString *oHttpBodyLengthString = [[NSString alloc] initWithFormat😠"%d", [oHttpBody length]];
[oRequest addValue😮HttpBodyLengthString forHTTPHeaderField😠"Content-Length"];
NSError *oError = [[NSError alloc] init];
NSHTTPURLResponse *oResponseCode = nil;
NSData *oResponseData = [NSURLConnection
sendSynchronousRequest😮Request
returningResponse😮ResponseCode
error😮Error];
NSString *strResult = [[NSString alloc]
initWithData😮ResponseData
encoding:NSUTF8StringEncoding];
// Setting label value to HTTP server's response
[label setText:strResult];