How do I get the last HTTP Status Code from a UIWebView?

后端 未结 9 2157
栀梦
栀梦 2020-12-08 16:43

I would like to detect when a page load request give to a UIWebView has returned a status code in the 5xx or 4xx range.

I\'ve setup the delegate for the web view a

9条回答
  •  情话喂你
    2020-12-08 17:24

    What about implementing webViewDidFinishLoad: on your UIWebViewDelegate, and using the request property of the UIWebView to access the headers you're interested in? Something like this (untested):

    - (void)webViewDidFinishLoad:(UIWebView *)webView {
      NSString* theStatus = [[webView request] valueForHTTPHeaderField:@"Status"];
    }
    

提交回复
热议问题