2014-09-19 38 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