好的。我一直在使用原始HTTP請求,發現我可以將原始HTTP響應發佈到NSLog中,並且我幾乎將原始HTTP請求分解爲NSLog。我現在只是升遷卡住了。HTTP請求標頭
代碼示例
NSString *CurrentWebURL = webView.request.URL.absoluteString;
NSURLSession *session= [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
[[session dataTaskWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:CurrentWebURL]] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSDictionary *requestdictionary = [request allHTTPHeaderFields];
NSLog(@"----shouldStartLoadWithRequest Raw HTTPRequest Start ----");
for (NSString *Object in [requestdictionary allKeys]) {
NSLog(@"%@: %@",Object, [requestdictionary objectForKey:Object]);
}
NSLog(@"----shouldStartLoadWithRequest Raw HTTPRequest Finish ----"] withlevel:SPECIAL_LOG);
}]resume];
原始請求:
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (iPad; CPU OS 7_0_6 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Mobile/11B651
應該向我展示 「獲取:URL」, 「HOST」, 「連接:保持活動」, 「接受編碼」,「接受」,「Cookie」,「連接」,「接受語言」和「用戶代理」。
我的問題是爲什麼它只顯示「接受」和「用戶代理」?
製作要求:
NSURL *url = [NSURL URLWithString:PortalURL];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[request setHTTPShouldHandleCookies:YES];
[request setHTTPMethod: @"GET"];
提琴手請求跟蹤(沒有任何自定義頁眉):
GET http://URL/ HTTP/1.1
Host: Host.co.uk
Connection: keep-alive
Accept-Encoding: gzip, deflate
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Cookie: IsosecCookie=Chris%20Beckett
Connection: keep-alive
Accept-Language: en-gb
User-Agent: Mozilla/5.0 (iPad; CPU OS 7_0_6 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Mobile/11B651
中的NSLog日誌請求頭:
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (iPad; CPU OS 7_0_6 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Mobile/11B651
你能告訴你如何創建你的'request'對象並設置你的頭域嗎? – Stonz2
@ Stonz2爲您添加了請求對象,我不想設置任何自定義標題字段。 –