Strange HtmlUnit behavior (bug?)

Posted by roddik on Stack Overflow See other posts from Stack Overflow or by roddik
Published on 2010-02-11T14:15:16Z Indexed on 2010/03/29 19:43 UTC
Read the original article Hit count: 417

Filed under:
|

Hello. Take a look at this:

WebClient client = new WebClient();
WebRequestSettings wrs = new WebRequestSettings(new URL("http://stackoverflow.com/ping/?what-the-duck?"), HttpMethod.HEAD);
client.getPage(wrs);

Running this code results in throwing FileNotFoundException, because HTTP Status code on the page is 404 and getting the same page again with the GET method, with User-Agent set to Java-.... Why does it GET the page (it doesn't happen with "normal" status codes)? Is this a bug? Thanks

Here is the entire server response:

HTTP/1.1 404 Not Found
Cache-Control: private
Content-Length: 7502
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/7.5
Date: Thu, 11 Feb 2010 14:12:11 GMT

Where does it tell client to GET something? And how can I force WebClient to ignore it?

Here's a screenshot of HTTPDebugger: alt text The problem here is I don't understand why the second request is being sent and why is it sent with different useragent.

© Stack Overflow or respective owner

Related posts about java

Related posts about htmlunit