Sending SOAP request using HTTPPost (HttpClient 4.0)

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

Sending SOAP request using HTTPPost (HttpClient 4.0)

by arpita dhundia :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Folks,

I have run into a very odd problem.
I have to send a SOAP (xml data over HTTP Post) request to another server behind NTLM authentication. I am using HttpClient 4.0 for that.
The NTLM authentication works fine but when I try to send the xml data using StringEntity and set that Entity to the HTTPPpost Object, I am returned 400 error code, meaning "bad request".
I tried to see the exact request that HTTPClient is sending using WireShark and indeed the format of the request is not correct. The headers are repeated twice and the body too is not correctly placed (unfortunately I cant point out the exact mistake, but comparing it with a request that a soap client sends its different and seeming incorrect).

Is anybody aware of any problems related to StringEntity? Or maybe any other way I can send xml data using HttpPost method in HttpClient 4.0 API.

Any help would be highly appreciated, I am behind my deadline on this task :(.

Thanks!!

PS:- For better understanding, here is a snippet of the code:-

DefaultHttpClient client = new DefaultHttpClient();
        client.getAuthSchemes().register("ntlm", new NTLMSchemeFactory());
        client.getCredentialsProvider().setCredentials(
                new AuthScope("host", port, "domain"),
                new NTCredentials("username", "password", "domain",
                        "domain2"));

        HttpPost httpget = new HttpPost(
                "http://ip/ServerAPI/ServerCommandService.asmx");

        try {
            String soapRequest = "<?xml version=\"1.0\"encoding=\"utf-8\"?>"
                    + "<soap:Envelope "
                    + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
                    + "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
                    + "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\""
                    + "<soap:Body>"
                    + "<Login xmlns=\"http://videoos.net/2/XProtectCSServerCommand\">"
                    + "<instanceId>6a716afc-708e-479f-8b42-f97338d794f9</instanceId>"
                    + "<currentToken/>" + "</Login>" + "</soap:Body>"
                    + "</soap:Envelope>";


            httpget.addHeader("SOAPAction",
                    "\"http://videoos.net/2/XProtectCSServerCommand/Login\"");

            StringEntity strent= new StringEntity(soapRequest);
            strent.setContentType("text/xml; charset=utf-8");
            httpget.setEntity(strent);

            ResponseHandler<String> response = new BasicResponseHandler();
            String responseBody = client.execute(httpget, response);
            System.out.println(responseBody);
}catch(IOException ex)
{
ex.printStackTrace();
}



      Now, send attachments up to 25MB with Yahoo! India Mail. Learn how. http://in.overview.mail.yahoo.com/photos

Re: Sending SOAP request using HTTPPost (HttpClient 4.0)

by olegk :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

arpita dhundia wrote:

> Hello Folks,
>
> I have run into a very odd problem.
> I have to send a SOAP (xml data over HTTP Post) request to another server behind NTLM authentication. I am using HttpClient 4.0 for that.
> The NTLM authentication works fine but when I try to send the xml data using StringEntity and set that Entity to the HTTPPpost Object, I am returned 400 error code, meaning "bad request".
> I tried to see the exact request that HTTPClient is sending using WireShark and indeed the format of the request is not correct. The headers are repeated twice and the body too is not correctly placed (unfortunately I cant point out the exact mistake, but comparing it with a request that a soap client sends its different and seeming incorrect).
>
> Is anybody aware of any problems related to StringEntity? Or maybe any other way I can send xml data using HttpPost method in HttpClient 4.0 API.
>
> Any help would be highly appreciated, I am behind my deadline on this task :(.
>
> Thanks!!
>

Turn off 'expect-continue' handshaking.

Oleg

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


Re: Sending SOAP request using HTTPPost (HttpClient 4.0)

by arpita dhundia :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for the reply Oleg, could you guide a little how can I do that?

Regards,
Arpita

--- On Sat, 31/10/09, Oleg Kalnichevski <olegk@...> wrote:

From: Oleg Kalnichevski <olegk@...>
Subject: Re: Sending SOAP request using HTTPPost (HttpClient 4.0)
To: "HttpClient User Discussion" <httpclient-users@...>
Date: Saturday, 31 October, 2009, 4:40 AM

arpita dhundia wrote:

> Hello Folks,
>
> I have run into a very odd problem.
> I have to send a SOAP (xml data over HTTP Post) request to another server behind NTLM authentication. I am using HttpClient 4.0 for that.
> The NTLM authentication works fine but when I try to send the xml data using StringEntity and set that Entity to the HTTPPpost Object, I am returned 400 error code, meaning "bad request".
> I tried to see the exact request that HTTPClient is sending using WireShark and indeed the format of the request is not correct. The headers are repeated twice and the body too is not correctly placed (unfortunately I cant point out the exact mistake, but comparing it with a request that a soap client sends its different and seeming incorrect).
>
> Is anybody aware of any problems related to StringEntity? Or maybe any other way I can send xml data using HttpPost method in HttpClient 4.0 API.
>
> Any help would be highly appreciated, I am behind my deadline on this task :(.
>
> Thanks!!
>

Turn off 'expect-continue' handshaking.

Oleg

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




      Add whatever you love to the Yahoo! India homepage. Try now! http://in.yahoo.com/trynew

Re: Sending SOAP request using HTTPPost (HttpClient 4.0)

by thboileau :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

you can find documentation here
http://hc.apache.org/httpcomponents-client/tutorial/pdf/httpclient-tutorial.pdf

best regards,
Thierry Boileau

> Thanks for the reply Oleg, could you guide a little how can I do that?
>
> Regards,
> Arpita
>
> --- On Sat, 31/10/09, Oleg Kalnichevski <olegk@...> wrote:
>
> From: Oleg Kalnichevski <olegk@...>
> Subject: Re: Sending SOAP request using HTTPPost (HttpClient 4.0)
> To: "HttpClient User Discussion" <httpclient-users@...>
> Date: Saturday, 31 October, 2009, 4:40 AM
>
> arpita dhundia wrote:
>> Hello Folks,
>>
>> I have run into a very odd problem.
>> I have to send a SOAP (xml data over HTTP Post) request to another server behind NTLM authentication. I am using HttpClient 4.0 for that.
>> The NTLM authentication works fine but when I try to send the xml data using StringEntity and set that Entity to the HTTPPpost Object, I am returned 400 error code, meaning "bad request".
>> I tried to see the exact request that HTTPClient is sending using WireShark and indeed the format of the request is not correct. The headers are repeated twice and the body too is not correctly placed (unfortunately I cant point out the exact mistake, but comparing it with a request that a soap client sends its different and seeming incorrect).
>>
>> Is anybody aware of any problems related to StringEntity? Or maybe any other way I can send xml data using HttpPost method in HttpClient 4.0 API.
>>
>> Any help would be highly appreciated, I am behind my deadline on this task :(.
>>
>> Thanks!!
>>
>
> Turn off 'expect-continue' handshaking.
>
> Oleg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@...
> For additional commands, e-mail: httpclient-users-help@...
>
>
>
>
>      Add whatever you love to the Yahoo! India homepage. Try now! http://in.yahoo.com/trynew

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


Re: Sending SOAP request using HTTPPost (HttpClient 4.0)

by olegk :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

arpita dhundia wrote:
> Thanks for the reply Oleg, could you guide a little how can I do that?
>
> Regards,
> Arpita
>

DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE,
false);

Oleg

> --- On Sat, 31/10/09, Oleg Kalnichevski <olegk@...> wrote:
>
> From: Oleg Kalnichevski <olegk@...>
> Subject: Re: Sending SOAP request using HTTPPost (HttpClient 4.0)
> To: "HttpClient User Discussion" <httpclient-users@...>
> Date: Saturday, 31 October, 2009, 4:40 AM
>
> arpita dhundia wrote:
>> Hello Folks,
>>
>> I have run into a very odd problem.
>> I have to send a SOAP (xml data over HTTP Post) request to another server behind NTLM authentication. I am using HttpClient 4.0 for that.
>> The NTLM authentication works fine but when I try to send the xml data using StringEntity and set that Entity to the HTTPPpost Object, I am returned 400 error code, meaning "bad request".
>> I tried to see the exact request that HTTPClient is sending using WireShark and indeed the format of the request is not correct. The headers are repeated twice and the body too is not correctly placed (unfortunately I cant point out the exact mistake, but comparing it with a request that a soap client sends its different and seeming incorrect).
>>
>> Is anybody aware of any problems related to StringEntity? Or maybe any other way I can send xml data using HttpPost method in HttpClient 4.0 API.
>>
>> Any help would be highly appreciated, I am behind my deadline on this task :(.
>>
>> Thanks!!
>>
>
> Turn off 'expect-continue' handshaking.
>
> Oleg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@...
> For additional commands, e-mail: httpclient-users-help@...
>
>
>
>
>       Add whatever you love to the Yahoo! India homepage. Try now! http://in.yahoo.com/trynew


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


Re: Sending SOAP request using HTTPPost (HttpClient 4.0)

by arpita dhundia :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I tried setting the expect 100 continue param false but the problem still persists..
I am performimg very simple stpes, using NTLm authentication, creating an HTTPPost object and attaching a StringEntity object to it, on which I have written the xml data.
Wireshark shows that the post data is not in the right format, hence the recieving server sends back an HTTP 400 error.
I am not sure what I am doing wrong, or maybe what can I do to avoid this error.

Please help.

Thanks,
Arpita



--- On Sat, 7/11/09, Thierry Boileau <thboileau@...> wrote:

From: Thierry Boileau <thboileau@...>
Subject: Re: Sending SOAP request using HTTPPost (HttpClient 4.0)
To: "HttpClient User Discussion" <httpclient-users@...>
Date: Saturday, 7 November, 2009, 5:03 PM

Hello,

you can find documentation here
http://hc.apache.org/httpcomponents-client/tutorial/pdf/httpclient-tutorial.pdf

best regards,
Thierry Boileau

> Thanks for the reply Oleg, could you guide a little how can I do that?
>
> Regards,
> Arpita
>
> --- On Sat, 31/10/09, Oleg Kalnichevski <olegk@...> wrote:
>
> From: Oleg Kalnichevski <olegk@...>
> Subject: Re: Sending SOAP request using HTTPPost (HttpClient 4.0)
> To: "HttpClient User Discussion" <httpclient-users@...>
> Date: Saturday, 31 October, 2009, 4:40 AM
>
> arpita dhundia wrote:
>> Hello Folks,
>>
>> I have run into a very odd problem.
>> I have to send a SOAP (xml data over HTTP Post) request to another server behind NTLM authentication. I am using HttpClient 4.0 for that.
>> The NTLM authentication works fine but when I try to send the xml data using StringEntity and set that Entity to the HTTPPpost Object, I am returned 400 error code, meaning "bad request".
>> I tried to see the exact request that HTTPClient is sending using WireShark and indeed the format of the request is not correct. The headers are repeated twice and the body too is not correctly placed (unfortunately I cant point out the exact mistake, but comparing it with a request that a soap client sends its different and seeming incorrect).
>>
>> Is anybody aware of any problems related to StringEntity? Or maybe any other way I can send xml data using HttpPost method in HttpClient 4.0 API.
>>
>> Any help would be highly appreciated, I am behind my deadline on this task :(.
>>
>> Thanks!!
>>
>
> Turn off 'expect-continue' handshaking.
>
> Oleg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@...
> For additional commands, e-mail: httpclient-users-help@...
>
>
>
>
>      Add whatever you love to the Yahoo! India homepage. Try now! http://in.yahoo.com/trynew

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




      The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/

Re: Sending SOAP request using HTTPPost (HttpClient 4.0)

by olegk :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

arpita dhundia wrote:
> I tried setting the expect 100 continue param false but the problem still persists..
 >
> I am performimg very simple stpes, using NTLm authentication, creating an HTTPPost object and attaching a StringEntity object to it, on which I have written the xml data.
> Wireshark shows that the post data is not in the right format, hence the recieving server sends back an HTTP 400 error.
> I am not sure what I am doing wrong, or maybe what can I do to avoid this error.
>

Doe not use Wireshark. Use wire log of HttpClient instead

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

Oleg


> Please help.
>
> Thanks,
> Arpita
>
>
>
> --- On Sat, 7/11/09, Thierry Boileau <thboileau@...> wrote:
>
> From: Thierry Boileau <thboileau@...>
> Subject: Re: Sending SOAP request using HTTPPost (HttpClient 4.0)
> To: "HttpClient User Discussion" <httpclient-users@...>
> Date: Saturday, 7 November, 2009, 5:03 PM
>
> Hello,
>
> you can find documentation here
> http://hc.apache.org/httpcomponents-client/tutorial/pdf/httpclient-tutorial.pdf
>
> best regards,
> Thierry Boileau
>
>> Thanks for the reply Oleg, could you guide a little how can I do that?
>>
>> Regards,
>> Arpita
>>
>> --- On Sat, 31/10/09, Oleg Kalnichevski <olegk@...> wrote:
>>
>> From: Oleg Kalnichevski <olegk@...>
>> Subject: Re: Sending SOAP request using HTTPPost (HttpClient 4.0)
>> To: "HttpClient User Discussion" <httpclient-users@...>
>> Date: Saturday, 31 October, 2009, 4:40 AM
>>
>> arpita dhundia wrote:
>>> Hello Folks,
>>>
>>> I have run into a very odd problem.
>>> I have to send a SOAP (xml data over HTTP Post) request to another server behind NTLM authentication. I am using HttpClient 4.0 for that.
>>> The NTLM authentication works fine but when I try to send the xml data using StringEntity and set that Entity to the HTTPPpost Object, I am returned 400 error code, meaning "bad request".
>>> I tried to see the exact request that HTTPClient is sending using WireShark and indeed the format of the request is not correct. The headers are repeated twice and the body too is not correctly placed (unfortunately I cant point out the exact mistake, but comparing it with a request that a soap client sends its different and seeming incorrect).
>>>
>>> Is anybody aware of any problems related to StringEntity? Or maybe any other way I can send xml data using HttpPost method in HttpClient 4.0 API.
>>>
>>> Any help would be highly appreciated, I am behind my deadline on this task :(.
>>>
>>> Thanks!!
>>>
>> Turn off 'expect-continue' handshaking.
>>
>> Oleg
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@...
>> For additional commands, e-mail: httpclient-users-help@...
>>
>>
>>
>>
>>      Add whatever you love to the Yahoo! India homepage. Try now! http://in.yahoo.com/trynew
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@...
> For additional commands, e-mail: httpclient-users-help@...
>
>
>
>
>       The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/


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


Parent Message unknown RE: Sending SOAP request using HTTPPost (HttpClient 4.0)

by Brijesh Deo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The best way to do this would be to try and simulate the steps using
HttpClient in the same way as a browser does.

If you have Mozilla Firefox, use the HttpFox plugin and see the sequence
of GET and POST request and responses when you interact with your web
server using the browser. Then try to follow the same/similar sequence
of GET and POSTs using the HttpClient and it should work.

I had a similar problem, where after the authentication (login) to the
server, there was an implicit POST from the browser using a javascript
code which happened without the user having to POST anything explicitly.
When I was trying to login using the HttpClient and then trying to do a
GET on something else, it was failing. Then I did a similar POST (the
implicit POST done by javascript) using HttpClient after the login POST
and then I was able to proceed successfully.

So, the problem is not necessarily with the HttpClient. It could be how
your server likes to be interacted with....find that out and do the same
using HttpClient and I am sure it will work. I have been using
HttpClient to perform quite complicated series of POSTs, GETs and
Redirects in my project....and it's been working fine and as expected.
But I have had to find the proper sequence by observing the browser
behavior first.

Hope this helps...


Thanks,
Brijesh


-----Original Message-----
From: Oleg Kalnichevski [mailto:olegk@...]
Sent: Tuesday, November 10, 2009 3:10 AM
To: HttpClient User Discussion
Subject: Re: Sending SOAP request using HTTPPost (HttpClient 4.0)

arpita dhundia wrote:
> I tried setting the expect 100 continue param false but the problem
still persists..
 >
> I am performimg very simple stpes, using NTLm authentication, creating
an HTTPPost object and attaching a StringEntity object to it, on which I
have written the xml data.
> Wireshark shows that the post data is not in the right format, hence
the recieving server sends back an HTTP 400 error.
> I am not sure what I am doing wrong, or maybe what can I do to avoid
this error.
>

Doe not use Wireshark. Use wire log of HttpClient instead

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

Oleg


> Please help.
>
> Thanks,
> Arpita
>
>
>
> --- On Sat, 7/11/09, Thierry Boileau <thboileau@...> wrote:
>
> From: Thierry Boileau <thboileau@...>
> Subject: Re: Sending SOAP request using HTTPPost (HttpClient 4.0)
> To: "HttpClient User Discussion" <httpclient-users@...>
> Date: Saturday, 7 November, 2009, 5:03 PM
>
> Hello,
>
> you can find documentation here
>
http://hc.apache.org/httpcomponents-client/tutorial/pdf/httpclient-tutor
ial.pdf
>
> best regards,
> Thierry Boileau
>
>> Thanks for the reply Oleg, could you guide a little how can I do
that?

>>
>> Regards,
>> Arpita
>>
>> --- On Sat, 31/10/09, Oleg Kalnichevski <olegk@...> wrote:
>>
>> From: Oleg Kalnichevski <olegk@...>
>> Subject: Re: Sending SOAP request using HTTPPost (HttpClient 4.0)
>> To: "HttpClient User Discussion" <httpclient-users@...>
>> Date: Saturday, 31 October, 2009, 4:40 AM
>>
>> arpita dhundia wrote:
>>> Hello Folks,
>>>
>>> I have run into a very odd problem.
>>> I have to send a SOAP (xml data over HTTP Post) request to another
server behind NTLM authentication. I am using HttpClient 4.0 for that.
>>> The NTLM authentication works fine but when I try to send the xml
data using StringEntity and set that Entity to the HTTPPpost Object, I
am returned 400 error code, meaning "bad request".
>>> I tried to see the exact request that HTTPClient is sending using
WireShark and indeed the format of the request is not correct. The
headers are repeated twice and the body too is not correctly placed
(unfortunately I cant point out the exact mistake, but comparing it with
a request that a soap client sends its different and seeming incorrect).
>>>
>>> Is anybody aware of any problems related to StringEntity? Or maybe
any other way I can send xml data using HttpPost method in HttpClient
4.0 API.
>>>
>>> Any help would be highly appreciated, I am behind my deadline on
this task :(.

>>>
>>> Thanks!!
>>>
>> Turn off 'expect-continue' handshaking.
>>
>> Oleg
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@...
>> For additional commands, e-mail: httpclient-users-help@...
>>
>>
>>
>>
>>      Add whatever you love to the Yahoo! India homepage. Try now!
http://in.yahoo.com/trynew
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@...
> For additional commands, e-mail: httpclient-users-help@...
>
>
>
>
>       The INTERNET now has a personality. YOURS! See your Yahoo!
Homepage. http://in.yahoo.com/


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


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