3

I have a method that created a NSURLRequest. If I load this NSURLRequest in a UIWebView, there are some redirections that I catch with - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType.

How can I intercept this redirections without load my request in a UIWebView ? (I do not want it at all)

Anthony
  • 2,801
  • 3
  • 30
  • 49

3 Answers3

3

Well, you have to tell us how you're loading it to begin with. Are you using NSURLConnection? Then use the -connection:willSendRequest:redirectResponse: delegate method. Be sure to read the docs to understand when it will be called. It is often called just because the framework tweaked your request, before actually communicating with anything, so not every invocation is a redirect.

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
  • i want to avoid NSURLConnection from handling any redirects and want to read the response when status code is 302 i tried many things including returning nil/same request from `connection:willSendRequest:redirectResponse` but no avail in java apache client it works with setting "http.protocol.handle-redirects" to false see the link of java doc thats what i want do in ios http://hc.apache.org/httpcomponents-client-4.2.x/tutorial/html/httpagent.html#d5e1169 – Yadnesh Jan 19 '15 at 07:45
1

if i understand well you want to catch the request and not load it in the webview. If that's what you want to do, just make your method return NO.

           - (BOOL)webView:(UIWebView *)webView 
shouldStartLoadWithRequest:(NSURLRequest *)request 
            navigationType:(UIWebViewNavigationType)navigationType.
Nicolas Manzini
  • 8,379
  • 6
  • 63
  • 81
0

You can subclass NSURLCache in order to intercept any url requests.

This example: http://cocoawithlove.com/2010/09/substituting-local-data-for-remote.html demonstrates using a subclass to load local files in place of remote files, but you should also be able to use a similar subclass to cancel requests or perform other actions you need.

Anthony Mattox
  • 7,048
  • 6
  • 43
  • 59