1. bilalwahla-ios-forum's Avatar
    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:oRequestUrl];

    [oRequest setHTTPMethod:@"POST"];
    [oRequest addValue:@"text/plain" forHTTPHeaderField:@"Content-Type"];

    NSMutableData *oHttpBody = [NSMutableData data];
    [oHttpBody appendData:[@"iPhone" dataUsingEncoding:NSUTF8StringEncoding]];
    [oRequest setHTTPBody:oHttpBody];
    NSString *oHttpBodyLengthString = [[NSString alloc] initWithFormat:@"%d", [oHttpBody length]];
    [oRequest addValue:oHttpBodyLengthString forHTTPHeaderField:@"Content-Length"];

    NSError *oError = [[NSError alloc] init];
    NSHTTPURLResponse *oResponseCode = nil;
    NSData *oResponseData = [NSURLConnection

    NSString *strResult = [[NSString alloc]

    // Setting label value to HTTP server's response
    [label setText:strResult];
    10-21-2010 04:02 PM
  2. bilalwahla-ios-forum's Avatar
    If you are wondering what I am doing in my Java-based HTTP server, please find the code below:

    Socket client = soc.accept();
    InputStreamReader ir = new InputStreamReader(soc.getInputStream());
    BufferedReader br = new BufferedReader(ir);
    String s = br.readLine();
    System.out.println("Request recieved from client: " + s);

    This string I'm trying to print out is always empty.

    Many thanks
    Last edited by bilalwahla-ios-forum; 10-24-2010 at 12:14 PM.
    10-24-2010 12:10 PM