Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

apache httpclient

 
James Whelan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working on an app using the apache httpclient connecting to a http post base API. Im able to authenticate and println my retun. errorcode = 0 and Seesionis=1234567. now I need to repost this seesionid to other methods. This is an app so there is no cookie to store. Im assuming I could store this to memory, or does httpclient do that for me? if so how does that work when reposting.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would there be no cookie to store? You're making an HTTP connection, right? I think cookie support is turned on by default, but you should check that to make sure. And *I think* you need to reuse the same HttpClient object, each may have have its own set of cookies.
 
James Whelan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, Im not going to be using a web browser. just the app. it will be talking to an API server within an app.

I use the apache httpclient to execute the post

https://my.api.domain/api/login.do?account=myaccount&username=myname&password=mypassword

I can get a seesion to retun. lets say seesion id=xyz123

now I can execute within that method with a seesionid variable but if I go out of scope that variable is not longer valid. I'd like to have an authentication class and just use that for session getting and run url repost like

https://my.api.domain/api/downloadDocument.do?sessionid=xyz123&exportid=123

I'm new to java so I assume apaches common httpclient has a was to manage session withing an app, like for an andriod app.


 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, you assume only a browser can handle cookies - not so. Cookies are handled by an HTTP client. That can be a browser, but it can also be a library like HttpClient.

Did my comments about turning on cookie support (assuming it's not on by default, which may well be the case), and reusing the HttpClient object make sense? If not, start working through http://hc.apache.org/httpclient-3.x/cookies.html, and also study the cookie example code at http://svn.apache.org/viewvc/httpcomponents/oac.hc3x/trunk/src/examples/
 
James Whelan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I was confused about how cookies were used in the httpclient library and assumed it was only for browser usage. I'm going to go thought the cookie docs and sample code and rework the app. I'm sure i'm on the right path now. Thank You.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic