Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
182 views
in Technique[技术] by (71.8m points)

java - ClientProtocolException in httpClient.execute(httpget, responseHandler)

I am using the following code to request xml from a web server:

HttpClient httpclient = new DefaultHttpClient()
try 
{
    HttpGet httpget = new HttpGet("http://63.255.173.242/get_public_tbl.cgi?A=1");              
    ResponseHandler responseHandler = new BasicResponseHandler();
    String responseBody = httpclient.execute(httpget, responseHandler);
    System.out.println(responseBody);
}
catch (ClientProtocolException e)
{
    e.printStackTrace();
}
catch (IOException e)
{
    e.printStackTrace();
} 
finally 
{
    httpclient.getConnectionManager().shutdown();
}

I get a clientProtocolException when I call httpclient.execute(httpget, responseHandler). The url works just fine in a web browser, it returns the xml and the browser displays it.

Any ideas why I would get a clientProtocolException and yet the browser handles it just fine?

Edit 1:

Looking at the protocol exception the detail message is: "The server failed to respond with a valid HTTP response". I cannot change the web server that I am hitting. Is there a way to ignore this and just access the response?

Edit 2:

I have found that the server is not sending back a complete header. Is there a way to access the contents of the response even when a broken header is returned?

Edit 3: I edited the ip address to be the real IP address I am hitting. Any help would be much appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As your code seems to be correct, you have to figure out: Is this the client's fault (invalid request), or the server's fault (invalid response). To do that, use a http trace utitlity and compare the requests of a browser to that of your client. You'll also be able to see the raw response from the server, if there is any. If you can't figure it out then, add the raw request and response to your question and someone might be able to help.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...