我尝试使用NSURLRequest
将NSString发送到服务器而不使用键值对,但将响应作为空值。有人可以提供相关信息吗?
提前谢谢你......
我尝试过的代码:
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:someUrl];
[request setHTTPMethod:@"POST"];
NSString *post = [NSString stringWithFormat:@"%@",someString];
NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:postData];
[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[someUrl host]];
NSError *error=nil;
// generates an autoreleased NSURLConnection
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection start];
NSURLResponse *response = nil;
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *string = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:returnData //1
options:kNilOptions
error:&error];
NSLog(@" json %@ ",json);