hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mblanc <blanc.matth...@gmail.com>
Subject Re: GET request using httpclient4.0.1
Date Tue, 13 Jul 2010 13:06:06 GMT

Hi,

I had the same problem and ended up doing this :

HttpGet request = new HttpGet(url);
HttpResponse httpResponse = new DefaultHttpClient().execute(new HttpHost(new
URL(url).getHost()), request);

(url is a string representation of a URL which can have a hostname
containing underscores)

which worked.

Regards

Mat.



Ken Krugler wrote:
> 
> Hi Udit,
> 
>> Thanks Ken !
>> Some where I had assumed that problem.
>> But one thing i want to share that as you said I should use httpcore
>> directly, I have built my application with having  
>> "httpcore-4.0.1.jar" and
>> "httpclient-4.0.1.jar" both.
>> so can you tell how can i use the Httpcore-4.0.1.I will try and If I  
>> found
>> something then I get back to you.
> 
> Unfortunately I've never used HttpCore directly. I know there have  
> been some past posts on this list about how to potentially reuse some  
> pieces of HttpClient, while interacting directly with HttpCore, but I  
> don't have anything concrete to offer.
> 
> I might wind up building my own version of HttpClient that uses a  
> custom URI class, which wraps the standard URI class other than  
> changes needed for non-standard subdomains. If so, I'll post my notes  
> about how that worked.
> 
> -- Ken
> 
> 
>> Ken Krugler wrote:
>>>
>>> Hi Udit,
>>>
>>> I believe the problem is that technically the subdomain
>>> ("donotdelete_httpclient", in your case) can't have underscores.
>>>
>>> So the URI class will return null for the hostname.
>>>
>>> The same thing would happen if you had a subdomain that started  
>>> with a
>>> "-", for example "-angelcries.blogspot.com"
>>>
>>> In HttpClient 3.x, there was a custom URI class that was more  
>>> lenient,
>>> but in 4.x the standard Java URI class is used.
>>>
>>> Even though these are technically invalid hostnames, most (all?) DNS
>>> servers will resolve them properly, which is why the URL works in a
>>> browser, but fails with HttpClient 4.
>>>
>>> I believe Oleg's standard response is that you should use HttpCore
>>> directly if you need to work with non-standard hostnames.
>>>
>>> -- Ken
>>>
>>> On Jun 9, 2010, at 6:18am, Udit Bhatnagar wrote:
>>>
>>>>
>>>> Hi,
>>>>
>>>> I am using httpclient4.0.1.jar for get request in my code.earlier i
>>>> was
>>>> using commons-httpclient-3.1.jar for the same.
>>>>
>>>> For httpclient4.0.1.jar
>>>> ====================================================
>>>> My code block is as follows :
>>>>
>>>> conn = new DefaultHttpClient();
>>>> HttpHost host = new HttpHost("s3.amazonaws.com",80);
>>>> HttpGet request = new HttpGet();
>>>>
>>>> request.setURI(new
>>>> java.net.URI("https://donotdelete_httpclient.s3.amazonaws.com/4F265439.jpg?AWSAccessKeyId=AKIAINHDRCMKC5GUSNFA&Expires=1276089613&Signature=Xxm%2FmOttPqs0F0jvx%2Fv%2FTQCJPsg%3D
>>>> "));
>>>> request.setParams(params);
>>>>
>>>> HttpResponse response = conn.execute(request);
>>>> response.setParams(params);
>>>>
>>>>
>>>> While Executing this request (red marked line)I am getting an
>>>> exception as
>>>> "Host name may not be null"(illegal argument exception) and If i run
>>>> this
>>>> URI on browser then it is running fine.
>>>>
>>>> =====================================================
>>>> For commons-httpclient-3.1.jar
>>>>
>>>> My code block  for same URI is as follows :
>>>>
>>>> HttpClient httpClient = new HttpClient();
>>>> HostConfiguration secureHostConfig = new HostConfiguration();
>>>>
>>>> GetMethod method = null;
>>>> method = new
>>>> GetMethod(https://donotdelete_httpclient.s3.amazonaws.com/4F265439.jpg?AWSAccessKeyId=AKIAINHDRCMKC5GUSNFA&Expires=1276089613&Signature=Xxm%2FmOttPqs0F0jvx%2Fv%2FTQCJPsg%3D
>>>> );
>>>>
>>>> statusCode = httpClient.executeMethod(secureHostConfig, method);
>>>>
>>>> For this code block it is running fine.
>>>> =======================================================
>>>>
>>>>
>>>> Can any one help me what I am missing out as I want to upgrade
>>>> commons-httpclient-3.1 to httpclient4.0.1.
>>>>
>>>> Thanks and regards to your responses.
>>>>
>>>> Regards-
>>>>
>>>> Udit
>>>> -- 
>>>> View this message in context:
>>>> http://old.nabble.com/GET-request-using-httpclient4.0.1-tp28830292p28830292.html
>>>> Sent from the HttpClient-User mailing list archive at Nabble.com.
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>>>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>>>
>>>
>>> --------------------------------------------
>>> Ken Krugler
>>> +1 530-210-6378
>>> http://bixolabs.com
>>> e l a s t i c   w e b   m i n i n g
>>>
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>>
>>>
>>>
>>
>> -- 
>> View this message in context:
>> http://old.nabble.com/GET-request-using-httpclient4.0.1-tp28830292p28838591.html
>> Sent from the HttpClient-User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>
> 
> --------------------------------------------
> Ken Krugler
> +1 530-210-6378
> http://bixolabs.com
> e l a s t i c   w e b   m i n i n g
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/GET-request-using-httpclient4.0.1-tp28830292p29150143.html
Sent from the HttpClient-User mailing list archive at Nabble.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