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);
}
// 执行请求
NSData *data = [NSURLConnection sendSynchronousRequest:req returningResponse:nil error:nil];
// 输出返回数据
NSString *returnString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"-----%@",returnString);
接收的返回数据为空什么都没有,我怀疑是根本就没有把username发到服务器上,请问这个怎么解决
------解决方案--------------------
no problems~!