是否可以在不使用键值对iphone的情况下将NSString发送到服务器?

时间:2014-03-07 07:21:20

标签: ios iphone objective-c nsurlrequest

我尝试使用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);

0 个答案:

没有答案