You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by bd...@bankdata.dk on 2004/11/12 12:32:36 UTC

404 Not Found




Hi all,

When using HttpClient to access a URL I'm getting a 404 Not Found response.
The strange thing is that when I access the same URL with
java.net.HttpURLConnection everything goes fine. First I thought that it
was a proxy problem, but then I guess that the HttpURLConnection request
should fail too. Does anybody have an idea about what I'm doing wrong?

Kind regards
/Morten

Here is some sample code and debug logging:

            String url = "http://the.server/test/script?key=value";

            HttpClient client = new HttpClient();
            GetMethod request = new GetMethod(url);
            client.executeMethod(request);
            byte[] responseBody = request.getResponseBody();
            String content = new String(responseBody);
            System.out.println("Got response from HttpClient [" + content +
"]");

            URL u = new URL(url);
            URLConnection uc = u.openConnection();
            HttpURLConnection connection = (HttpURLConnection) uc;
            connection.setDoInput(true);
            connection.setRequestMethod("GET");
            InputStream in = connection.getInputStream();
            StringBuffer sb = new StringBuffer();
            int c;
            while ((c = in.read()) != -1)
                  sb.append((char) c);

            String result = sb.toString();
            System.out.println("Got response from HttpURLConnection [" +
result + "]");
            in.close();
            connection.disconnect();

Logging:

2004/11/12 12:04:42:687 CET [DEBUG] HttpClient - -Java version: 1.3.1
2004/11/12 12:04:42:687 CET [DEBUG] HttpClient - -Java vendor: IBM
Corporation
2004/11/12 12:04:42:687 CET [DEBUG] HttpClient - -Java class path:
C:\WebSphere_Studio\Application_Developer\v51\runtimes\base_v5\java\jre\lib\rt.jar;C:\Workspace\Testbed\WebContent\WEB-INF\classes;C:\WebSphere_Studio\Application_Developer\v51\runtimes\base_v5\lib\j2ee.jar;C:\WebSphere_Studio\Application_Developer\v51\runtimes\base_v5\lib\servletevent.jar;C:\WebSphere_Studio\Application_Developer\v51\runtimes\base_v5\lib\ivjejb35.jar;C:\WebSphere_Studio\Application_Developer\v51\runtimes\base_v5\lib\runtime.jar;C:\Workspace\Testbed\WebContent\WEB-INF\lib\struts.jar;C:\jarview\YBU\Eksterne\Apache\commons-logging.jar;C:\Workspace\Testbed\WebContent\WEB-INF\lib\commons-httpclient.jar;C:\Workspace\Testbed\WebContent\WEB-INF\lib\commons-httpclient-2.0.2.jar
2004/11/12 12:04:42:687 CET [DEBUG] HttpClient - -Operating system name:
Windows XP
2004/11/12 12:04:42:687 CET [DEBUG] HttpClient - -Operating system
architecture: x86
2004/11/12 12:04:42:687 CET [DEBUG] HttpClient - -Operating system version:
5.1
2004/11/12 12:04:42:687 CET [DEBUG] HttpClient - -SUN 1.2: SUN (DSA
key/parameter generation; DSA signing; SHA-1, MD5 digests; SecureRandom;
X.509 certificates; JKS keystore)
2004/11/12 12:04:42:747 CET [DEBUG] HttpConnection -
-HttpConnection.setSoTimeout(0)
2004/11/12 12:04:42:747 CET [DEBUG] HttpMethodBase - -Execute loop try 1
2004/11/12 12:04:42:757 CET [DEBUG] header - ->> "GET /test/script
?key=value HTTP/1.1[\r][\n]"
2004/11/12 12:04:42:757 CET [DEBUG] HttpMethodBase - -Adding Host request
header
2004/11/12 12:04:42:767 CET [DEBUG] header - ->> "User-Agent: Jakarta
Commons-HttpClient/2.0.2[\r][\n]"
2004/11/12 12:04:42:767 CET [DEBUG] header - ->> "Host: the.server[\r][\n]"
2004/11/12 12:04:42:787 CET [DEBUG] header - ->> "[\r][\n]"
2004/11/12 12:04:42:787 CET [DEBUG] header - -<< "HTTP/1.1 404 Not
Found[\r][\n]"
2004/11/12 12:04:42:787 CET [DEBUG] header - -<< "Date: Fri, 12 Nov 2004
11:04:45 GMT[\r][\n]"
2004/11/12 12:04:42:787 CET [DEBUG] header - -<< "Server:
IBM_HTTP_SERVER[\r][\n]"
2004/11/12 12:04:42:797 CET [DEBUG] header - -<< "Transfer-Encoding:
chunked[\r][\n]"
2004/11/12 12:04:42:797 CET [DEBUG] header - -<< "Content-Type: text/html;
charset=iso-8859-1[\r][\n]"
2004/11/12 12:04:42:797 CET [DEBUG] HttpConnection -
-HttpConnection.getSoTimeout()
2004/11/12 12:04:42:807 CET [WARN] HttpMethodBase - -Going to buffer
response body of large or unknown size. Using getResponseAsStream instead
is recommended.
2004/11/12 12:04:42:807 CET [DEBUG] HttpMethodBase - -Buffering response
body
2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "d"
2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "6"
2004/11/12 12:04:42:807 CET [DEBUG] content - -<< " "
2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "[\r]"
2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "[\n]"
2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "<!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML 2.0//EN">[\n]"
2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "<HTML><HEAD>[\n]"
2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "<TITLE>404 Not
Found</TITLE>[\n]"
2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "</HEAD><BODY>[\n]"
2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "<H1>Not Found</H1>[\n]"
2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "The requested URL
/digidok/Overvaagning was not found on this server.<P>[\n]"
2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "</BODY></HTML>[\n]"
2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "[\r]"
2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "[\n]"
Got response from HttpClient [<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0
//EN">
<HTML><HEAD>
<TITLE>404 Not Found</TITLE>
</HEAD><BODY>
<H1>Not Found</H1>
The requested URL /digidok/Overvaagning was not found on this server.<P>
</BODY></HTML>
]

2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "0"
2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "[\r]"
2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "[\n]"
2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "[\r]"
2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "[\n]"
2004/11/12 12:04:42:807 CET [DEBUG] HttpMethodBase - -Resorting to protocol
version default close connection policy
2004/11/12 12:04:42:807 CET [DEBUG] HttpMethodBase - -Should NOT close
connection, using HTTP/1.1.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: Vedr.: Re: 404 Not Found

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Fri, Nov 12, 2004 at 03:01:22PM +0100, bdymob@bankdata.dk wrote:
> Sorry, that was me that forgot to rename a URI in the log (the real one was
> long and had no relevance to the question...
> 
> /Morten
>

All right. That explains it. Anyways, apparently there's something in
the HTTP request composed by HttpClient that causes the web server to
misinterpret the target url. Consider capturing the HTTP packets
generated by Sun's HttpUrlConnection using a traffic analyzer such as
ethereal and comparing them to those generaged by HttpClient. 

Does the real target url hapen to contain any non-ascii (apparently Danish)
characters? 

Oleg

> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Vedr.: Re: 404 Not Found

Posted by bd...@bankdata.dk.



Hi Oleg,

>
> 2004/11/12 12:04:42:757 CET [DEBUG] header - ->> "GET /test/script
> > ?key=value HTTP/1.1[\r][\n]"
> > ...
> 2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "The requested URL
> > /digidok/Overvaagning was not found on this server.<P>[\n]"
> >
> The server response looks a bit fishy to me. The request url does not
> correspond to the resource the server apparently attempted to locate. At
> the same time there has been no redirects or anything. It looks like
> there's some kind of issue with the server-side script
>

Sorry, that was me that forgot to rename a URI in the log (the real one was
long and had no relevance to the question...

/Morten


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: 404 Not Found

Posted by Oleg Kalnichevski <ol...@apache.org>.
Hi Morten

2004/11/12 12:04:42:757 CET [DEBUG] header - ->> "GET /test/script
> ?key=value HTTP/1.1[\r][\n]"
> ...
2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "The requested URL
> /digidok/Overvaagning was not found on this server.<P>[\n]"
> 
The server response looks a bit fishy to me. The request url does not
correspond to the resource the server apparently attempted to locate. At
the same time there has been no redirects or anything. It looks like
there's some kind of issue with the server-side script

Hope this clarifies things a little

Oleg



On Fri, Nov 12, 2004 at 12:32:36PM +0100, bdymob@bankdata.dk wrote:
> 
> 
> 
> 
> Hi all,
> 
> When using HttpClient to access a URL I'm getting a 404 Not Found response.
> The strange thing is that when I access the same URL with
> java.net.HttpURLConnection everything goes fine. First I thought that it
> was a proxy problem, but then I guess that the HttpURLConnection request
> should fail too. Does anybody have an idea about what I'm doing wrong?
> 
> Kind regards
> /Morten
> 
> Here is some sample code and debug logging:
> 
>             String url = "http://the.server/test/script?key=value";
> 
>             HttpClient client = new HttpClient();
>             GetMethod request = new GetMethod(url);
>             client.executeMethod(request);
>             byte[] responseBody = request.getResponseBody();
>             String content = new String(responseBody);
>             System.out.println("Got response from HttpClient [" + content +
> "]");
> 
>             URL u = new URL(url);
>             URLConnection uc = u.openConnection();
>             HttpURLConnection connection = (HttpURLConnection) uc;
>             connection.setDoInput(true);
>             connection.setRequestMethod("GET");
>             InputStream in = connection.getInputStream();
>             StringBuffer sb = new StringBuffer();
>             int c;
>             while ((c = in.read()) != -1)
>                   sb.append((char) c);
> 
>             String result = sb.toString();
>             System.out.println("Got response from HttpURLConnection [" +
> result + "]");
>             in.close();
>             connection.disconnect();
> 
> Logging:
> 
> 2004/11/12 12:04:42:687 CET [DEBUG] HttpClient - -Java version: 1.3.1
> 2004/11/12 12:04:42:687 CET [DEBUG] HttpClient - -Java vendor: IBM
> Corporation
> 2004/11/12 12:04:42:687 CET [DEBUG] HttpClient - -Java class path:
> C:\WebSphere_Studio\Application_Developer\v51\runtimes\base_v5\java\jre\lib\rt.jar;C:\Workspace\Testbed\WebContent\WEB-INF\classes;C:\WebSphere_Studio\Application_Developer\v51\runtimes\base_v5\lib\j2ee.jar;C:\WebSphere_Studio\Application_Developer\v51\runtimes\base_v5\lib\servletevent.jar;C:\WebSphere_Studio\Application_Developer\v51\runtimes\base_v5\lib\ivjejb35.jar;C:\WebSphere_Studio\Application_Developer\v51\runtimes\base_v5\lib\runtime.jar;C:\Workspace\Testbed\WebContent\WEB-INF\lib\struts.jar;C:\jarview\YBU\Eksterne\Apache\commons-logging.jar;C:\Workspace\Testbed\WebContent\WEB-INF\lib\commons-httpclient.jar;C:\Workspace\Testbed\WebContent\WEB-INF\lib\commons-httpclient-2.0.2.jar
> 2004/11/12 12:04:42:687 CET [DEBUG] HttpClient - -Operating system name:
> Windows XP
> 2004/11/12 12:04:42:687 CET [DEBUG] HttpClient - -Operating system
> architecture: x86
> 2004/11/12 12:04:42:687 CET [DEBUG] HttpClient - -Operating system version:
> 5.1
> 2004/11/12 12:04:42:687 CET [DEBUG] HttpClient - -SUN 1.2: SUN (DSA
> key/parameter generation; DSA signing; SHA-1, MD5 digests; SecureRandom;
> X.509 certificates; JKS keystore)
> 2004/11/12 12:04:42:747 CET [DEBUG] HttpConnection -
> -HttpConnection.setSoTimeout(0)
> 2004/11/12 12:04:42:747 CET [DEBUG] HttpMethodBase - -Execute loop try 1
> 2004/11/12 12:04:42:757 CET [DEBUG] header - ->> "GET /test/script
> ?key=value HTTP/1.1[\r][\n]"
> 2004/11/12 12:04:42:757 CET [DEBUG] HttpMethodBase - -Adding Host request
> header
> 2004/11/12 12:04:42:767 CET [DEBUG] header - ->> "User-Agent: Jakarta
> Commons-HttpClient/2.0.2[\r][\n]"
> 2004/11/12 12:04:42:767 CET [DEBUG] header - ->> "Host: the.server[\r][\n]"
> 2004/11/12 12:04:42:787 CET [DEBUG] header - ->> "[\r][\n]"
> 2004/11/12 12:04:42:787 CET [DEBUG] header - -<< "HTTP/1.1 404 Not
> Found[\r][\n]"
> 2004/11/12 12:04:42:787 CET [DEBUG] header - -<< "Date: Fri, 12 Nov 2004
> 11:04:45 GMT[\r][\n]"
> 2004/11/12 12:04:42:787 CET [DEBUG] header - -<< "Server:
> IBM_HTTP_SERVER[\r][\n]"
> 2004/11/12 12:04:42:797 CET [DEBUG] header - -<< "Transfer-Encoding:
> chunked[\r][\n]"
> 2004/11/12 12:04:42:797 CET [DEBUG] header - -<< "Content-Type: text/html;
> charset=iso-8859-1[\r][\n]"
> 2004/11/12 12:04:42:797 CET [DEBUG] HttpConnection -
> -HttpConnection.getSoTimeout()
> 2004/11/12 12:04:42:807 CET [WARN] HttpMethodBase - -Going to buffer
> response body of large or unknown size. Using getResponseAsStream instead
> is recommended.
> 2004/11/12 12:04:42:807 CET [DEBUG] HttpMethodBase - -Buffering response
> body
> 2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "d"
> 2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "6"
> 2004/11/12 12:04:42:807 CET [DEBUG] content - -<< " "
> 2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "[\r]"
> 2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "[\n]"
> 2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "<!DOCTYPE HTML PUBLIC
> "-//IETF//DTD HTML 2.0//EN">[\n]"
> 2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "<HTML><HEAD>[\n]"
> 2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "<TITLE>404 Not
> Found</TITLE>[\n]"
> 2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "</HEAD><BODY>[\n]"
> 2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "<H1>Not Found</H1>[\n]"
> 2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "The requested URL
> /digidok/Overvaagning was not found on this server.<P>[\n]"
> 2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "</BODY></HTML>[\n]"
> 2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "[\r]"
> 2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "[\n]"
> Got response from HttpClient [<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0
> //EN">
> <HTML><HEAD>
> <TITLE>404 Not Found</TITLE>
> </HEAD><BODY>
> <H1>Not Found</H1>
> The requested URL /digidok/Overvaagning was not found on this server.<P>
> </BODY></HTML>
> ]
> 
> 2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "0"
> 2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "[\r]"
> 2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "[\n]"
> 2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "[\r]"
> 2004/11/12 12:04:42:807 CET [DEBUG] content - -<< "[\n]"
> 2004/11/12 12:04:42:807 CET [DEBUG] HttpMethodBase - -Resorting to protocol
> version default close connection policy
> 2004/11/12 12:04:42:807 CET [DEBUG] HttpMethodBase - -Should NOT close
> connection, using HTTP/1.1.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org