【发布时间】:2015-04-29 12:11:15
【问题描述】:
我正在开发一个应用程序,因为我曾经通过 WebServices 将我的联系号码发送到服务器。这里我获取我的联系号码一个数组,然后我通过 webservices 发送联系人数组。下面的代码,
NSString *myRequestString1 = [[NSString alloc] initWithFormat:@"contact_numbers=%@",MobiileArray ];
NSData *myRequestData = [ NSData dataWithBytes: [ myRequestString1 UTF8String ] length: [ myRequestString1 length ] ];
NSMutableURLRequest *request = [ [ NSMutableURLRequest alloc ] initWithURL: [ NSURL URLWithString:@"http://myproject.in/myproject-contacts.php"]];
[request setHTTPMethod: @"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
[request setHTTPBody: myRequestData];
NSURLResponse *response;
NSError *err;
NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse:&response error:&err];
NSError* error;
NSMutableArray* result = [NSJSONSerialization JSONObjectWithData:returnData
options:kNilOptions
error:&error];
NSLog(@"result: %@", result);
但响应为空,我的代码有错误吗?可以给我推荐一下吗谢谢。
【问题讨论】:
-
你遇到了什么错误?
-
这听起来很傻,但你确定你的问题出在客户端吗?也许您的网络服务没有返回您所期望的。
-
是的,我通过 POST 和 GET 方法做了很多服务,但在这里我很挣扎@Zil
标签: ios objective-c iphone xcode nsmutableurlrequest