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 Andre Brito <an...@gmail.com> on 2010/10/26 13:57:37 UTC
Trouble with post in HttpClient 4.0.3
Hey guys.
We have 2 peace of software that imports a few data from sites. I was using
HttpClient 3.1 and it was great! But then, one of the sites started to
complain (maybe because of our access, I don't know) and was throwing
exceptions about the certificate.
So I decided to change from 3.1 to 4.0.3. Ok, I can do the GET methods, but
I can't build the POST. I'm getting a 417 HttpStatus code (expectation
failed). In HttpClient 3.1, I was building the POST like this:
PostMethod method = new
PostMethod("http://www.receita.fazenda.gov.br/PessoaJuridica/CNPJ/cnpjreva/valida.asp");
method.addParameter("origem", "comprovante");
method.addParameter("cnpj", cnpj);
method.addParameter("idLetra", captcha);
method.addParameter("idSom", "");
method.addParameter("submit1", "Consultar");
method.addParameter("search_type", "cnpj");
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new
DefaultHttpMethodRetryHandler(3, false));
In HttpClient I'm doing like this:
HttpPost post = new HttpPost(url);
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("origem", "comprovante"));
parameters.add(new BasicNameValuePair("cnpj", cnpj));
parameters.add(new BasicNameValuePair("idLetra", captcha));
parameters.add(new BasicNameValuePair("idSom", ""));
parameters.add(new BasicNameValuePair("submit1", "Consultar"));
parameters.add(new BasicNameValuePair("search_type", "cnpj"));
post.setEntity(new UrlEncodedFormEntity(parameters, "UTF-8"));
Is that correct? If that so, I can't find a reason why in 3.1 is working and
in 4.0.3 is not.
Can anyone give me a direction?
--
View this message in context: http://old.nabble.com/Trouble-with-post-in-HttpClient-4.0.3-tp30056777p30056777.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
RE: Is there any simple Asynchronous Http Client can use?
Posted by Tatu Saloranta <co...@yahoo.com>.
For what it's worth, there is also this:
http://github.com/AsyncHttpClient
which is NIO-based asynchronous client, and it is being actively developed (devs from Sonatype and Ning fwiw).
-+ Tatu +-
--- On Wed, 10/27/10, Micky Lee <mi...@cyberpowersystems.com.tw> wrote:
> From: Micky Lee <mi...@cyberpowersystems.com.tw>
> Subject: RE: Is there any simple Asynchronous Http Client can use?
> To: "'HttpClient User Discussion'" <ht...@hc.apache.org>
> Date: Wednesday, October 27, 2010, 6:03 AM
> Dear Oleg,
>
> OK, thanks for your reply.
>
> I will try the Jetty HTTP client and hope to see one day
> the NIO Apache HttpClient will come out as stable release.
>
> Sincerely,
> Mciky
>
> -----Original Message-----
> From: Oleg Kalnichevski [mailto:olegk@apache.org]
>
> Sent: Wednesday, October 27, 2010 6:37 PM
> To: HttpClient User Discussion
> Subject: Re: Is there any simple Asynchronous Http Client
> can use?
>
>
> > Hi Micky
>
> > The async version of Apache HttpClient based on NIO is
> still in a very
> > early (pre-ALPHA) stage of development. Lots essential
> bits are still
> > missing including a callback mechanism for completed
> HTTP exchanges.
>
> > Please note there is nothing that prevents you from
> adding asynchronous
> > callbacks to the stock version of Apache HttpClient
> 4.x with a fairly
> > modest amount of custom code.
>
> > If you are absolutely sure you want a NIO based HTTP
> client, there is at
> > least a few available. I can recommend Jetty HTTP
> client.
>
> > Hope this helps
>
> > Oleg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
RE: Is there any simple Asynchronous Http Client can use?
Posted by Micky Lee <mi...@cyberpowersystems.com.tw>.
Dear Oleg,
OK, thanks for your reply.
I will try the Jetty HTTP client and hope to see one day the NIO Apache HttpClient will come out as stable release.
Sincerely,
Mciky
-----Original Message-----
From: Oleg Kalnichevski [mailto:olegk@apache.org]
Sent: Wednesday, October 27, 2010 6:37 PM
To: HttpClient User Discussion
Subject: Re: Is there any simple Asynchronous Http Client can use?
> Hi Micky
> The async version of Apache HttpClient based on NIO is still in a very
> early (pre-ALPHA) stage of development. Lots essential bits are still
> missing including a callback mechanism for completed HTTP exchanges.
> Please note there is nothing that prevents you from adding asynchronous
> callbacks to the stock version of Apache HttpClient 4.x with a fairly
> modest amount of custom code.
> If you are absolutely sure you want a NIO based HTTP client, there is at
> least a few available. I can recommend Jetty HTTP client.
> Hope this helps
> Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
Re: Is there any simple Asynchronous Http Client can use?
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2010-10-27 at 17:00 +0800, Micky Lee wrote:
> Hi,
>
> I want an asynchronous http client, and I found the svn repository: http://svn.apache.org/repos/asf/httpcomponents/httpasyncclient/
>
> I want a notify when the request has response with a callback function, but the AsyncHttpClient only has the API to do "awaitResponse ()" method to wait and block until there is response.
>
> I think the using of it may not be called an asynchronous http client.
>
> The test case in example org.apache.http.examples.nio.client. AsyncClientRequest is
>
...
> Any suggestion is welcome, thanks in advance.
>
>
> Sincerely,
> Micky
>
Hi Micky
The async version of Apache HttpClient based on NIO is still in a very
early (pre-ALPHA) stage of development. Lots essential bits are still
missing including a callback mechanism for completed HTTP exchanges.
Please note there is nothing that prevents you from adding asynchronous
callbacks to the stock version of Apache HttpClient 4.x with a fairly
modest amount of custom code.
If you are absolutely sure you want a NIO based HTTP client, there is at
least a few available. I can recommend Jetty HTTP client.
Hope this helps
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
Is there any simple Asynchronous Http Client can use?
Posted by Micky Lee <mi...@cyberpowersystems.com.tw>.
Hi,
I want an asynchronous http client, and I found the svn repository: http://svn.apache.org/repos/asf/httpcomponents/httpasyncclient/
I want a notify when the request has response with a callback function, but the AsyncHttpClient only has the API to do "awaitResponse ()" method to wait and block until there is response.
I think the using of it may not be called an asynchronous http client.
The test case in example org.apache.http.examples.nio.client. AsyncClientRequest is
----
...
HttpHost target = new HttpHost("www.google.ch", 80);
BasicHttpRequest request = new BasicHttpRequest("GET", "/");
HttpExchange[] httpx = new HttpExchange[10];
for (int i = 0; i < httpx.length; i++) {
httpx[i] = asynchttpclient.execute(target, request);
}
for (int i = 0; i < httpx.length; i++) {
HttpResponse response = httpx[i].awaitResponse(); // block here
if (response != null) {
System.out.println("Response: " + response.getStatusLine());
}
}
...
----
When I change the code to following, it blocks one by one and not the one I want, because I don't know which one will have response quickly.
----
...
HttpHost target = new HttpHost("www.google.ch", 80);
BasicHttpRequest request = new BasicHttpRequest("GET", "/");
HttpExchange[] httpx = new HttpExchange[10];
for (int i = 0; i < httpx.length; i++) {
httpx[i] = asynchttpclient.execute(target, request);
HttpResponse response = httpx[i].awaitResponse(); // block here
if (response != null) {
System.out.println("Response: " + response.getStatusLine());
}
}
...
----
Any suggestion is welcome, thanks in advance.
Sincerely,
Micky
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
Re: Trouble with post in HttpClient 4.0.3
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2010-10-27 at 05:11 -0700, Andre Brito wrote:
> Oleg,
>
> It worked! But why (now it's personal, hehe, I don't like to see that it's
> working and not knowing the reason)?
Not all web servers out there implement HTTP/1.1 fully (or correctly)
> I'm tyring to access HttpClient's
> website, but that seems to be down.
>
Works for me
http://hc.apache.org/
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
Re: Trouble with post in HttpClient 4.0.3
Posted by Andre Brito <an...@gmail.com>.
Oleg,
It worked! But why (now it's personal, hehe, I don't like to see that it's
working and not knowing the reason)? I'm tyring to access HttpClient's
website, but that seems to be down.
Thanks!
olegk wrote:
>
> On Tue, 2010-10-26 at 04:57 -0700, Andre Brito wrote:
>> Hey guys.
>> We have 2 peace of software that imports a few data from sites. I was
>> using
>> HttpClient 3.1 and it was great! But then, one of the sites started to
>> complain (maybe because of our access, I don't know) and was throwing
>> exceptions about the certificate.
>>
>> So I decided to change from 3.1 to 4.0.3. Ok, I can do the GET methods,
>> but
>> I can't build the POST. I'm getting a 417 HttpStatus code (expectation
>> failed). In HttpClient 3.1, I was building the POST like this:
>>
>> PostMethod method = new
>> PostMethod("http://www.receita.fazenda.gov.br/PessoaJuridica/CNPJ/cnpjreva/valida.asp");
>>
>> method.addParameter("origem", "comprovante");
>> method.addParameter("cnpj", cnpj);
>> method.addParameter("idLetra", captcha);
>> method.addParameter("idSom", "");
>> method.addParameter("submit1", "Consultar");
>> method.addParameter("search_type", "cnpj");
>> method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new
>> DefaultHttpMethodRetryHandler(3, false));
>>
>> In HttpClient I'm doing like this:
>>
>> HttpPost post = new HttpPost(url);
>>
>> List<NameValuePair> parameters = new ArrayList<NameValuePair>();
>> parameters.add(new BasicNameValuePair("origem", "comprovante"));
>> parameters.add(new BasicNameValuePair("cnpj", cnpj));
>> parameters.add(new BasicNameValuePair("idLetra", captcha));
>> parameters.add(new BasicNameValuePair("idSom", ""));
>> parameters.add(new BasicNameValuePair("submit1", "Consultar"));
>> parameters.add(new BasicNameValuePair("search_type", "cnpj"));
>>
>> post.setEntity(new UrlEncodedFormEntity(parameters, "UTF-8"));
>>
>> Is that correct? If that so, I can't find a reason why in 3.1 is working
>> and
>> in 4.0.3 is not.
>>
>> Can anyone give me a direction?
>
> Try disabling the 'expect: continue' handshaking.
>
> Oleg
>
>
>
> ---------------------------------------------------------------------
> 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/Trouble-with-post-in-HttpClient-4.0.3-tp30056777p30066545.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
Re: Trouble with post in HttpClient 4.0.3
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2010-10-26 at 04:57 -0700, Andre Brito wrote:
> Hey guys.
> We have 2 peace of software that imports a few data from sites. I was using
> HttpClient 3.1 and it was great! But then, one of the sites started to
> complain (maybe because of our access, I don't know) and was throwing
> exceptions about the certificate.
>
> So I decided to change from 3.1 to 4.0.3. Ok, I can do the GET methods, but
> I can't build the POST. I'm getting a 417 HttpStatus code (expectation
> failed). In HttpClient 3.1, I was building the POST like this:
>
> PostMethod method = new
> PostMethod("http://www.receita.fazenda.gov.br/PessoaJuridica/CNPJ/cnpjreva/valida.asp");
>
> method.addParameter("origem", "comprovante");
> method.addParameter("cnpj", cnpj);
> method.addParameter("idLetra", captcha);
> method.addParameter("idSom", "");
> method.addParameter("submit1", "Consultar");
> method.addParameter("search_type", "cnpj");
> method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new
> DefaultHttpMethodRetryHandler(3, false));
>
> In HttpClient I'm doing like this:
>
> HttpPost post = new HttpPost(url);
>
> List<NameValuePair> parameters = new ArrayList<NameValuePair>();
> parameters.add(new BasicNameValuePair("origem", "comprovante"));
> parameters.add(new BasicNameValuePair("cnpj", cnpj));
> parameters.add(new BasicNameValuePair("idLetra", captcha));
> parameters.add(new BasicNameValuePair("idSom", ""));
> parameters.add(new BasicNameValuePair("submit1", "Consultar"));
> parameters.add(new BasicNameValuePair("search_type", "cnpj"));
>
> post.setEntity(new UrlEncodedFormEntity(parameters, "UTF-8"));
>
> Is that correct? If that so, I can't find a reason why in 3.1 is working and
> in 4.0.3 is not.
>
> Can anyone give me a direction?
Try disabling the 'expect: continue' handshaking.
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org