• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Create post request with apache HttpClient

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all
I'm using HttpClient to create a post request. I send this req to a website but the reply isn't as expected.
My request needs to be formatted like this simple request:



This is the req generated by Internet Explorer and I need to replicate it programmatically with HttpClient.
I'm using something like



but the response from the server is not ok. The page returned from the server is an error page, it seems that maybe something is missing in the Post headers.
Printing the requestEntity request gives me the post request body and this is ok!
So maybe it's only a header problem.
I know that the 2 important headers are Content-Type and Content-Length, I have check them and they are ok.
The Content-Length is correctly set directly by the httpPostMethod.setRequestBody(parameters); and it returns the correct int body size value.
So I'm trying to set something like

but the reply is always the error page.
Someone knows how to configure a correct Post request with HttpClient based on these param?
Thanks
[ July 05, 2008: Message edited by: al nik ]
 
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May be what I'm saying is obvious, but did you print the request generated by the HttpClient and compare that with what generated by IE?

Also if you have control over server, can you get some info of what it expects but missing from your request?
 
al nik
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Santhosh Kumar, thanks for your reply
I don't have the control over the server. It seems that the prob is given by a redirect call that sets some cookies.
After my request the server returns a redirect to another page an in the http response headers there is a cookie that sets the ASP_sessionID and then redirect to another page.
I think that the client.executeMethod(httpPostMethod); method call the redirect automatically without send the cookies back to the server.
 
Put a gun against his head, pulled my trigger, now he's dead, that tiny ad sure bled
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic