2014-09-19 37 views
4

这仅在iOS 8上显示。对于早期版本,它没有问题。NSMutableURLRequest仅在iOS中为url添加附加标头8

实例:

对于iOS 7.1:

NSString *url = @"http://www.example.com/api/search?name=test&page=1"; 
NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] init]; 
[urlRequest setURL:[NSURL URLWithString:url]]; 

获取urlRequest作为

<NSMutableURLRequest: 0x7b787130> { URL: http://www.example.com/api/search?name=test&page=1 } 

对于iOS 8.0:

NSString *url = @"http://www.example.com/api/search?name=test&page=1"; 
NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] init]; 
[urlRequest setURL:[NSURL URLWithString:url]]; 

获取urlRequest

<NSMutableURLRequest: 0x7b6246d0> { URL: http://www.example.com/api/search?name=test&page=1, headers: (null) } 

错误适用于iOS 8.0:Error 400 (Bad Request)

+1

什么是实际的错误?这些消息似乎并不是说任何事情都是错的。 – 2014-09-19 14:39:22

+0

获取错误400(错误请求)!! 1。 – 2014-09-19 15:18:18

+0

您是否能够在服务器端捕获完整的URL并向我们展示其差异? – trojanfoe 2014-09-20 09:48:38

回答

0

你误认为日志。这只是意味着

URL = "http://www.example.com/api/search?name=test&page=1" 

headers = null 

你应该调试哪些实际标题:

NSLog("%@", urlRequest.allHTTPHeaderFields); 
+0

可能吧,但是OP不应该设置至少一个头(即'Content-Type'),这样服务器就知道它得到了什么? – trojanfoe 2014-09-22 10:31:11

+0

@trojanfoe和John Estropia其实我们在调用谷歌地图API ,当我们使用“[urlRequest setURL:[NSURL URLWithString:url]];”并打印nslog,然后获取网址,例如“https://maps.googleapis.com/maps/api/place/search/json?key=yourkey&location=lat,long&radius=radius,%20headers:%20(null)” – 2014-09-22 10:41:33

+0

@ AshutoshSrivastava你为什么要给我们滴水的细节?如何从一开始就充分披露权利? – trojanfoe 2014-09-22 10:42:59