aspose file tools*
The moose likes Other Open Source Projects and the fly likes apache httpclient Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "apache httpclient" Watch "apache httpclient" New topic
Author

apache httpclient

James Whelan
Greenhorn

Joined: Mar 09, 2013
Posts: 4
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
Marshal

Joined: Mar 22, 2005
Posts: 42292
    
  64
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.


Ping & DNS - my free Android networking tools app
James Whelan
Greenhorn

Joined: Mar 09, 2013
Posts: 4
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
Marshal

Joined: Mar 22, 2005
Posts: 42292
    
  64
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

Joined: Mar 09, 2013
Posts: 4
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: apache httpclient