File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes POST and Get Http Method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "POST and Get Http Method" Watch "POST and Get Http Method" New topic
Author

POST and Get Http Method

Alan So
Greenhorn

Joined: Sep 07, 2011
Posts: 10
Hi,

I need some asistance.
I am writing http code for POST and GET method. Below are the 2 APIs that will be call to the server.

APIs
1)http://ipaddress/platform/Login?user=test&password=test
2)http://ipaddress/platform/reportdata

The first API using POST method and the second API using GET method.

The second API should returns me XML data. But it returns me saiding that I am not authenticated.

Is there a way to verify that I am sucessfully being authenticated so that I can use the second API.

So Is there any parts that I miss out or had I make any mistakes?? Below is my code.



Please advice. Thanks.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42046
    
  64
If you used HttpClient for all requests, you could turn on its cookie support (which is, I assume, how authentication is controlled after a login).


Ping & DNS - my free Android networking tools app
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

And welcome to the Ranch!


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Alan So
Greenhorn

Joined: Sep 07, 2011
Posts: 10
Ulf Dittmer wrote:If you used HttpClient for all requests, you could turn on its cookie support (which is, I assume, how authentication is controlled after a login).


Apologize i dont quite understand your statement, can you show me where to change. Thanks.

Or you saiding that the http://ipaddress/platform/Login => should be using HttpCLient method follow by a Postmethod ? like what I did for the second API.
Alan So
Greenhorn

Joined: Sep 07, 2011
Posts: 10
Rob Spoor wrote:And welcome to the Ranch!


Thanks hopefully I can get all the helps in here.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42046
    
  64
ss sk wrote:
Ulf Dittmer wrote:If you used HttpClient for all requests, you could turn on its cookie support (which is, I assume, how authentication is controlled after a login).


Apologize i dont quite understand your statement, can you show me where to change. Thanks.

You're using HttpUrlConnection for the POST method, but HttpCLient for the GET method. If instead you were using HttpClient for both methods, you could use its cookie support for tracking any login cookies that may be set by the login (assuming cookies are used for that, which you need to find out).

Also, you need to change your display name -which is invalid- or your account will be closed soon.
Alan So
Greenhorn

Joined: Sep 07, 2011
Posts: 10
Ulf Dittmer wrote:
ss sk wrote:
Ulf Dittmer wrote:If you used HttpClient for all requests, you could turn on its cookie support (which is, I assume, how authentication is controlled after a login).


Apologize i dont quite understand your statement, can you show me where to change. Thanks.

You're using HttpUrlConnection for the POST method, but HttpCLient for the GET method. If instead you were using HttpClient for both methods, you could use its cookie support for tracking any login cookies that may be set by the login (assuming cookies are used for that, which you need to find out).

Also, you need to change your display name -which is invalid- or your account will be closed soon.


O ok. So both should use the HttpClient method instead. Any issues will be back again.



thanks once again.
 
Consider Paul's rocket mass heater.
 
subject: POST and Get Http Method