ios - Get the http response code from every UIWebView request -


i need check response status code while loading of url in webview fo. can consider of web application loading inside web view.so need track down every request withing webview , check out response code accordingly. finding response code, need use nsurlconnection inside uiwebview's delegate method "shouldstartloadwithrequest". thing -

- (bool) webview:(uiwebview *)webview shouldstartloadwithrequest:(nsurlrequest *)request         navigationtype:(uiwebviewnavigationtype)navigationtype{       nsurlconnection *conn = [nsurlconnection connectionwithrequest:request delegate:self];       if (conn == nil) {          nslog(@"cannot create connection");       }       return yes; } 

and nsurlconnectiondelegate --

- (void) connection:(nsurlconnection *)connection didreceiveresponse:(nsurlresponse *)response{     nslog(@"connection:didreceiveresponse");     [self log:@"received response."];     nshttpurlresponse *httpresponse = (nshttpurlresponse *) response;     int status = [httpresponse statuscode];      nslog(@"http status code: %d", status);     if (status == 200) {       nslog(@"response ok");     }     else {        nslog(@"response not ok");     } }  - (void) connection:(nsurlconnection *)connection didreceivedata:(nsdata *)data{    nslog(@"connection:didreceivedata"); }  - (void) connection:(nsurlconnection *)connection didfailwitherror:(nserror *)error{     nslog(@"connection:didfailwitherror - %@", error); }  - (void) connectiondidfinishloading:(nsurlconnection *)connection{    nslog(@"connectiondidfinishloading"); } 

but in process, there 2 calls on server. 1 uiwebview , other nsurlconnection. need single call server in able find status code. can please guide me in ?

i have implemented using

nsurlprotocol

. more details, can check here - nsurlprotocol


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -