This week's book giveaways are in the AI and JavaScript forums.
We're giving away four copies each of GANs in Action and WebAssembly in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

POST and Get Http Method

 
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.
 
Rancher
Posts: 43011
76
  • 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).
 
Sheriff
Posts: 21841
105
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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: 43011
76
  • 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.
 
This. Exactly this. This is what my therapist has been talking about. And now with a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!