HttpClient 4.0 httppost with parameters

View: New views
3 Messages — Rating Filter:   Alert me  

HttpClient 4.0 httppost with parameters

by Tobias Frei :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello together,
i am a new subsciber to this mailing list and i hope that anyone can help.

I am trying to simulate a login to a webpage via a httppost-request. When i send the post, i cannot see the pair parameter/value in the post-data section of my http sniffer. When i try to send the information via a webbrowser, i can see the right data in the sniffer. Strangely in the header of the request, i see a content-length of 23. Where are the parameters, what is wrong with my request?

Here is the relevant part of my code:

public void sendLoginInformation(){
               
                HttpPost httppost=new HttpPost(ggserverurl+phpexec);
                HttpResponse response;
                HttpEntity entity;
                BufferedReader bufferedreader;
                List <NameValuePair> parameters = new ArrayList <NameValuePair>();
                parameters.add(new BasicNameValuePair("a", "a"));
                parameters.add(new BasicNameValuePair("b", "b"));
                parameters.add(new BasicNameValuePair("c", "c"));
                parameters.add(new BasicNameValuePair("d", "e"));
                parameters.add(new BasicNameValuePair("e", "f"));
                parameters.add(new BasicNameValuePair("f", "g"));
                try {
                        UrlEncodedFormEntity sendentity = new UrlEncodedFormEntity(parameters, HTTP.UTF_8);
                        httppost.setEntity(sendentity);
                        response=httpclient.execute(httppost);
                        entity=response.getEntity();
                        /**if (entity!=null){
                                bufferedreader=new BufferedReader(new InputStreamReader (new BufferedInputStream(entity.getContent())));
                                int i;
                                for(i=0;i<1000;i++)System.out.println(bufferedreader.readLine());
                        }**/
                } catch (ClientProtocolException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        }

Help would be appreciated.

Thanks

Tobias
--
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01

--
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01

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


Re: HttpClient 4.0 httppost with parameters

by Charles François Rey-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I've tried your example and I do see the parameters in the analyzer (I  
use WireShark). Keep in mind that the actual http request and the  
content can be split across multiple frames, so be sure to examine the  
reassembled data, not below the TCP level.

The content-length of 23 corresponds effectively to your 6 key+values  
with '=' and 5 '&' in between.

On 27 oct. 09, at 13:17, Tobias Frei wrote:

> Hello together,
> i am a new subsciber to this mailing list and i hope that anyone can  
> help.
>
> I am trying to simulate a login to a webpage via a httppost-request.  
> When i send the post, i cannot see the pair parameter/value in the  
> post-data section of my http sniffer. When i try to send the  
> information via a webbrowser, i can see the right data in the  
> sniffer. Strangely in the header of the request, i see a content-
> length of 23. Where are the parameters, what is wrong with my request?
>
> Here is the relevant part of my code:
>
> public void sendLoginInformation(){
>
> HttpPost httppost=new HttpPost(ggserverurl+phpexec);
> HttpResponse response;
> HttpEntity entity;
> BufferedReader bufferedreader;
> List <NameValuePair> parameters = new ArrayList <NameValuePair>();
> parameters.add(new BasicNameValuePair("a", "a"));
> parameters.add(new BasicNameValuePair("b", "b"));
> parameters.add(new BasicNameValuePair("c", "c"));
> parameters.add(new BasicNameValuePair("d", "e"));
> parameters.add(new BasicNameValuePair("e", "f"));
> parameters.add(new BasicNameValuePair("f", "g"));
> try {
> UrlEncodedFormEntity sendentity = new  
> UrlEncodedFormEntity(parameters, HTTP.UTF_8);
> httppost.setEntity(sendentity);
> response=httpclient.execute(httppost);
> entity=response.getEntity();
> /**if (entity!=null){
> bufferedreader=new BufferedReader(new InputStreamReader (new  
> BufferedInputStream(entity.getContent())));
> int i;
> for(i=0;i<1000;i++)System.out.println(bufferedreader.readLine());
> }**/
> } catch (ClientProtocolException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
>
> Help would be appreciated.
>
> Thanks
>
> Tobias

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


Re: HttpClient 4.0 httppost with parameters

by olegk :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Tobias Frei wrote:

> Hello together,
> i am a new subsciber to this mailing list and i hope that anyone can help.
>
> I am trying to simulate a login to a webpage via a httppost-request. When i send the post, i cannot see the pair parameter/value in the post-data section of my http sniffer. When i try to send the information via a webbrowser, i can see the right data in the sniffer. Strangely in the header of the request, i see a content-length of 23. Where are the parameters, what is wrong with my request?
>
> Here is the relevant part of my code:
>
> public void sendLoginInformation(){
>
> HttpPost httppost=new HttpPost(ggserverurl+phpexec);
> HttpResponse response;
> HttpEntity entity;
> BufferedReader bufferedreader;
> List <NameValuePair> parameters = new ArrayList <NameValuePair>();
> parameters.add(new BasicNameValuePair("a", "a"));
> parameters.add(new BasicNameValuePair("b", "b"));
> parameters.add(new BasicNameValuePair("c", "c"));
> parameters.add(new BasicNameValuePair("d", "e"));
> parameters.add(new BasicNameValuePair("e", "f"));
> parameters.add(new BasicNameValuePair("f", "g"));
> try {
> UrlEncodedFormEntity sendentity = new UrlEncodedFormEntity(parameters, HTTP.UTF_8);
> httppost.setEntity(sendentity);
> response=httpclient.execute(httppost);
> entity=response.getEntity();
> /**if (entity!=null){
> bufferedreader=new BufferedReader(new InputStreamReader (new BufferedInputStream(entity.getContent())));
> int i;
> for(i=0;i<1000;i++)System.out.println(bufferedreader.readLine());
> }**/
> } catch (ClientProtocolException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
>
> Help would be appreciated.
>

You can use wire logging to see what gets sent across the wire

http://hc.apache.org/httpcomponents-client/logging.html

Oleg


> Thanks
>
> Tobias


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