NSURL *URL = [NSURL URLWithString:@"http://"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
request.HTTPMethod = @"POST";
NSString *params = @"json=deepak";
NSData *data = [params dataUsingEncoding:NSUTF8StringEncoding];
[request addValue:@"8bit" forHTTPHeaderField:@"Content-Transfer-Encoding"];
[request addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request addValue:[NSString stringWithFormat:@"%i", [data length]] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:data];
NSURLResponse *responce;
NSError *error;
NSData *returnData = [ NSURLConnection sendSynchronousRequest:request returningResponse:&responce error:&error];
NSString *content = [NSString stringWithUTF8String:[returnData bytes]];
NSLog(@"responseData: %@", content);
大家好,我正在使用stackOverflow本身的代码,并且写的答案是有效的,但是我得到了
来自 php 服务器的“响应数据 = null”
我的简单服务器代码是
$json = CJSON::decode($_POST['json'],TRUE); 回声 CJSON::encode($json);