ios - HTTP Request headers -
ios - HTTP Request headers -
okay. i've been working raw http request , found out can post raw http response nslog , i've cracked raw http request nslog. i'm abit stuck now.
code example
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 ----"); (nsstring *object in [requestdictionary allkeys]) { nslog(@"%@: %@",object, [requestdictionary objectforkey:object]); } nslog(@"----shouldstartloadwithrequest raw httprequest finish ----"] withlevel:special_log); }]resume];
raw request:
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 mac os x) applewebkit/537.51.1 (khtml, gecko) mobile/11b651
it should showing me "get:url", "host", "connection: keep-alive", "accept-encoding", "accept", "cookie", "connection", "accept-language" , "user-agent".
my question why showing "accept" , "user-agent"?
making request:
nsurl *url = [nsurl urlwithstring:portalurl]; nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:url cachepolicy:nsurlrequestuseprotocolcachepolicy timeoutinterval:60.0]; [request sethttpshouldhandlecookies:yes]; [request sethttpmethod: @"get"];
fiddler request trace (without custom headers):
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 mac os x) applewebkit/537.51.1 (khtml, gecko) mobile/11b651
logging request headers in 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 mac os x) applewebkit/537.51.1 (khtml, gecko) mobile/11b651
i've come conclusion it's not possible raw http request in ios nsurlrequest, you're able "accept" , "user-agent".
however i've done work around, raw http request i've used php headers. know it's not best solution works , it's great beingness able log info without having maintain going through proxy fiddler or charles proxy.
ios code
nsurl *phpurl = ([nsurl urlwithstring:[nsstring stringwithformat:@"http://office.isosec.co.uk/audit/testrequest.php?"]]); request = [[nsmutableurlrequest alloc] initwithurl:phpurl cachepolicy:nsurlrequestuseprotocolcachepolicy timeoutinterval:10.0]; [request sethttpmethod: @"get"]; [request sethttpshouldhandlecookies:yes]; nsurlconnection *connection = [[nsurlconnection alloc] initwithrequest:request delegate:self startimmediately:no]; phpresponse = [nsmutabledata data]; if( connection == nil ) { [viewcontroller remotelog:[nsstring stringwithformat:@"phprequest connection failed"] withlevel:special_log]; } else { [viewcontroller remotelog:[nsstring stringwithformat:@"phprequest connection started"] withlevel:special_log]; [connection scheduleinrunloop:[nsrunloop mainrunloop] formode:nsdefaultrunloopmode]; [connection start]; }
php code
foreach (getallheaders() $name => $value) { echo "$name: $value,"; }
ios objective-c http-headers httprequest
Comments
Post a Comment