title: UIWebView: Why does the request not time out when using a non-existant hostname?
body: <p>My situation is this:</p>
  
  <ul>
  <li>I have a <code>UIWebView</code> which makes a POST request to a URL where the hostname is provided by the user.</li>
  <li>When the hostname does not exist, I need to timeout so that I can alert the user to say that they should check the their settings.</li>
  </ul>
  
  <p>What is happening:</p>
  
  <p>I make a request like this:</p>
  
  <pre><code>NSString *theURL = [NSString stringWithFormat:@"https://%@%@", _hostname, LOGIN_PART_URL];
  NSString *body = [NSString stringWithFormat:@"Username=%@&amp;Password=%@", _username, _password];
  
  NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:theURL] 
                                                             cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                         timeoutInterval:_timeoutInSecs];
  
  
  
  [request setHTTPMethod: @"POST"];
  [request setHTTPBody: [body dataUsingEncoding: NSUTF8StringEncoding]];
  
  [web loadRequest:request];
  </code></pre>
  
  <p>When the hostname does not exist on the network, I do not get any timeout response. </p>
  
  <p>I have implemented all delegate methods of <code>UIWebViewDelegate</code>, and I get the following called in order when I use a non-existent hostname:</p>
  
  <ol>
  <li><code>webView: shouldStartLoadWithRequest: navigationType:</code>
  <ul>
  <li>(returns true always for testing)</li>
  </ul></li>
  <li><code>webViewDidStartLoad</code></li>
  </ol>
  
  <p>And that's it - nothing after that. </p>
  
  <p>I'm surprised that <code>webViewDidStartLoad</code> gets called, as this would suggest that it found the URL and thinks it can get data back from it. But it can't as the URL does not exist!</p>
  
  <p>Am I doing something wrong here?</p>
  
  <p>I have a workaround which I am going to implement, which uses an <code>NSTimer</code> to see if a response has been received within the timeout period. However, I am having issues with cancelling a request for a <code>UIWebView</code> - but that's a topic for my next SO question!</p>
  
  <p>So my questions:</p>
  
  <ol>
  <li>Is it correct for <code>webViewDidStartLoad</code> to be called on an invalid URL?</li>
  <li>Should I be seeing a request timeout error returned, with the way I have setup my request?</li>
  </ol>
  
  <p>Thanks in advance!!</p>
  
  <p>Stretch :)</p>