Saturday, October 5, 2013

Php server to send "username" and receives the returned data

str_post = @ "username";
NSString * ipdk = [[NSString alloc] initWithFormat: @ "http://192.168.1.104/post_android_data.php"];
NSURL * url = [NSURL URLWithString: ipdk];

NSMutableURLRequest * req = [NSMutableURLRequest requestWithURL: url];
NSString * msgLength = [NSString stringWithFormat: @ "% d", [str_post length]];
[Req addValue: @ "application / x-www-form-urlencoded" forHTTPHeaderField: @ "Content-Type"];
[Req addValue: msgLength forHTTPHeaderField: @ "Content-Length"];
[Req setHTTPMethod: @ "POST"];
[Req setHTTPBody: [str_post dataUsingEncoding: NSUTF8StringEncoding]];

conn = [[NSURLConnection alloc] initWithRequest: req delegate: self];

NSLog (@ "conn% @", conn);

if (conn) {
webData = [NSMutableData data];
NSLog (@ "webdata -----% @", webData);
}

/ / Execute the request
NSData * data = [NSURLConnection sendSynchronousRequest: req returningResponse: nil error: nil];
/ / Output return data
NSString * returnString = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];

NSLog (@ "-----% @", returnString);

Received return data is empty nothing, I suspect that is simply not the username sent to the server, and ask how to solve this

No comments:

Post a Comment