aspose 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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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: 39575
    
  27
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 - updated with new look and Ping home screen widget
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19555
    
  16

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: 39575
    
  27
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: POST and Get Http Method
 
Similar Threads
Logging into a forum
java.net.Connect Exception: Connection refused: connect
file upload from action
Problem HTTPSURLConnection for Siteminder authentictaion
Fake a post request from java class