• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

POST and Get Http Method

 
Alan So
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch!
 
Alan So
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:And welcome to the Ranch!


Thanks hopefully I can get all the helps in here.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic