【发布时间】:2010-11-22 08:51:15
【问题描述】:
基本上我想设置
Content-Type: application/json;
为了调用 dot net web 服务并让它返回 json 到 iphone 应用程序。
目前有
NSString * jsonres = [[NSString alloc] initWithContentsOfURL:url];我需要什么来发出阻塞请求?
【问题讨论】:
标签: iphone objective-c content-type
基本上我想设置
Content-Type: application/json;
为了调用 dot net web 服务并让它返回 json 到 iphone 应用程序。
目前有
NSString * jsonres = [[NSString alloc] initWithContentsOfURL:url];我需要什么来发出阻塞请求?
【问题讨论】:
标签: iphone objective-c content-type
您需要使用 NSURLMutableRequest,在这里您可以为内容类型和排序添加标头,这是参考,http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSMutableURLRequest_Class/Reference/Reference.html#//apple_ref/occ/cl/NSMutableURLRequest,一旦您设置了您的请求,您就可以使用此方法添加值 - (void)addValue :(NSString *)HTTPHeaderField 的值:(NSString *) 类似的字段
[request setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
【讨论】: