title: Specifying HTTP referer in UIWebView
body: <p>How can we set HTTP referer in embedded UIWebView?</p>
  
  <p>I had gone through <a href="https://stackoverflow.com/questions/7913305/specifying-http-referer-in-embedded-uiwebview">this</a> but still not got success.</p>
  
  <p><strong>1.</strong> In <code>viewDidLoad</code>, I wrote this code,</p>
  
  <pre><code>[objWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"MY_URL"]]];
  </code></pre>
  
  <p><strong>Here is my code :</strong></p>
  
  <pre><code>- (BOOL) webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType) navigationType 
  {
      NSDictionary *headers = [request allHTTPHeaderFields];
      BOOL hasReferer = [headers objectForKey:@"Referer"]!=nil;
      if (hasReferer) {
          // .. is this my referer?
          return YES;
      } else {
          // relaunch with a modified request
          dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
              dispatch_async(dispatch_get_main_queue(), ^{
                  NSURL *url = [request URL];
                  NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
                  [request setHTTPMethod:@"GET"];
                  [request setValue:@"Referer link" forHTTPHeaderField:@"Referer"];
                  [objWebView loadRequest:request];
              });
          });
          return NO;
      }
  }
  </code></pre>
  
  <p><strong>2.</strong> I had tried this also in <code>viewDidLoad</code></p>
  
  <pre><code>NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"MY_URL"]];
  [request setValue:@"Referel URL" forHTTPHeaderField:@"Referer"];
  [objWebView loadRequest:request];
  </code></pre>
  
  <p>But doesn't got success yet.</p>
  
  <p>Please help me solve this problem or tell me is there any problem with this code or not?</p>
  
  <p>Hope I presented question clearly.</p>