hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Todd Wilson" <t...@screen-scraper.com>
Subject "Unable to parse header" issue
Date Wed, 09 Aug 2006 03:13:10 GMT
Greetings,

Can't seem to find anything on this in Bugzilla or the list archives, so
I thought I'd throw it out to the group before submitting a bug.

This code:

----------------------------------------------------------
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.params.HttpMethodParams;

HttpClient client = new HttpClient();

GetMethod method = new GetMethod(
"http://212.50.188.107/cgi-win/vebra.cgi?details1?src=vebra&PropertyCode=1007003/ASHGR/38878/3"
);

try 
{
  // Execute the method.
  int statusCode = client.executeMethod(method);

  if (statusCode != HttpStatus.SC_OK) 
	{
    System.out.println("Method failed: " + method.getStatusLine());
  }

  // Read the response body.
  byte[] responseBody = method.getResponseBody();

  // Deal with the response.
  response = new String( responseBody );

	System.out.println( "Result from get: " + response );
} 
catch (Exception e) 
{
  System.out.println("Error: " + e.getMessage());
}
finally 
{
  // Release the connection.
  method.releaseConnection();
}
----------------------------------------------------------

Produces this exception:

----------------------------------------------------------
org.apache.commons.httpclient.ProtocolException: Unable to parse header:
HTTP/1.0 200 OK
	at org.apache.commons.httpclient.HttpParser.parseHeaders(Ljava.io.InputStream;Ljava.lang.String;)[Lorg.apache.commons.httpclient.Header;(Unknown
Source)
	at org.apache.commons.httpclient.HttpMethodBase.readResponseHeaders(Lorg.apache.commons.httpclient.HttpState;Lorg.apache.commons.httpclient.HttpConnection;)V(Unknown
Source)
	at org.apache.commons.httpclient.HttpMethodBase.readResponse(Lorg.apache.commons.httpclient.HttpState;Lorg.apache.commons.httpclient.HttpConnection;)V(Unknown
Source)
	at org.apache.commons.httpclient.HttpMethodBase.execute(Lorg.apache.commons.httpclient.HttpState;Lorg.apache.commons.httpclient.HttpConnection;)I(Unknown
Source)
	at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(Lorg.apache.commons.httpclient.HttpMethod;)V(Unknown
Source)
	at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(Lorg.apache.commons.httpclient.HttpMethod;)V(Unknown
Source)
	at org.apache.commons.httpclient.HttpClient.executeMethod(Lorg.apache.commons.httpclient.HostConfiguration;Lorg.apache.commons.httpclient.HttpMethod;Lorg.apache.commons.httpclient.HttpState;)I(Unknown
Source)
	at org.apache.commons.httpclient.HttpClient.executeMethod(Lorg.apache.commons.httpclient.HttpMethod;)I(Unknown
Source)
----------------------------------------------------------

If I try the HTTP request manually via telnet, here's what I get for the
HTTP response:

----------------------------------------------------------
HTTP/1.1 200 OK
Server: Microsoft-IIS/4.0
Date: Tue, 08 Aug 2006 16:31:46 GMT
HTTP/1.0 200 OK
Content-type: Text/HTML

<HTML>
  <HEAD>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html;
    charset=iso-8859-1">
<title>Burwell -   1 bed Flat/ Maisonette</title>
<script language="JavaScript" >
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->
.
.
.
----------------------------------------------------------

What do you think?  I'm honestly not sure what the cause is.  I copied
the HTTP response directly from a command prompt window, but it's
possible there could be some other white space in there that I didn't
include.

By the way, I realize the URL is completely malformed, but it seems to
work just fine in a browser.  The server is also probably doing who
knows what contrary to the HTTP spec, but such it is.

Thanks,

Todd Wilson

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


Mime
View raw message