hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Charles François Rey <charlesfr....@gmail.com>
Subject Re: Calling servlet help (HttpClient 4.0)
Date Fri, 04 Dec 2009 09:47:24 GMT
Well, the idea is to try to set the "Accept" header of the request, so that the media type
requested is compatible with what the servlets are configured to serve:

HttpGet httpget = new HttpGet("...");
httpget.setRequestHeader("Accept", "text/xml");

If it still doesn't work, try to tweak the media type, i.e. "application/xml", ...

You can learn more about the Accept header in RFC 2616, section 14.1.

Hope this helps.

On 4 déc. 2009, at 03:59, scook@seanet.com wrote:

> Can you expand on your answer a bit?  The accept header in the servlet or
> some API call (setRequest...() - what value?) in the http client?  The
> servlets set to return text/xml BTW.
> 
> I've also tried it using straight Java HttpUrlConnection, get same result.
> 
> Thanks for the help
> Steve
> 
>> Have you tried to set the "Accept" header of your request to the proper
>> media type ? Without it, your server might consider that you expect the
>> default, e.g. text/html, and won't serve you the xml. That's my guess.
>> 
>> On 2 déc. 2009, at 04:25, scook@seanet.com wrote:
>> 
>>> Hi,
>>> 
>>> Please excuse a newbie question but how do I get back the XML content
>>> back
>>> from a servlet.  All I seem to get is the index.html web page..
>>> 
>>> Basic call is:
>>> 
>>> HttpClient httpclient = new DefaultHttpClient();
>>> HttpGet httpget = new
>>>  HttpGet("http://localhost:8080/wc_server?task=get_results");
>>> HttpResponse response = httpclient.execute(httpget);
>>> 
>>> HttpEntity entity = response.getEntity();
>>> 
>>> if (entity != null)
>>> {
>>>   long len = entity.getContentLength();
>>>   if (len != -1 ) // && len < 8192)
>>>   {
>>>       System.out.println(EntityUtils.toString(entity));
>>>   }
>>> }
>>> 
>>> 
>>> Whats returned is the index.html page in that servlets top directory,
>>> not
>>> the XML data for that method call.  I get the same results with either:
>>> 
>>> HttpGet("http://localhost:8080/wc_server?task=get_results");
>>> 
>>> or
>>> 
>>> HttpGet("http://localhost:8080/wc_server");
>>> 
>>> It seems like it's not getting/processing the '?task=get_results'
>>> 
>>> If I remove the index.html file from the servlet directory it just
>>> errors
>>> back...
>>> 
>>> Thanks
>>> Steve Cook
>>> scook@seanet.com

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


Mime
View raw message