Solved

Constructing a POST HTTPS Request (EMPHASIS ON USERNAME & PASSWORD)

Posted on 2011-09-29
15
424 Views
Last Modified: 2012-05-12
How can I chuck in user credentials (username and password) in an HTTPS POST request in Java??!
0
Comment
Question by:snajalm
  • 8
  • 7
15 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 36814142
Normally, that's no different from http:

http://www.exampledepot.com/egs/java.net/Auth.html
0
 

Author Comment

by:snajalm
ID: 36814183
But how do you setRequestProperty to construct your POST method?!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36814336
That's a different question, but

http://www.exampledepot.com/egs/java.net/Post.html
0
 

Author Comment

by:snajalm
ID: 36814368
But there is nothing in this link...
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36814426
0
 

Author Comment

by:snajalm
ID: 36814556
But this link doesn't say anything about how to add "username" and "password" to the POST arguments before sending the request!  
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36814605
Normally you don't do that - authentication is part of the protocol and the responsibility of the Authenticator. If in your case you do, then it would be no different from any other post parameters
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:snajalm
ID: 36815037
so would it be something like,

comm.setRequestProperty("user", userName);
comm.setRequestProperty("password", password);

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36815098
If the server expects them to arrive as headers, then yes
0
 

Author Comment

by:snajalm
ID: 36898372
Can you please let me know of all the possible ways of constructing a post request?  I just want to send the username and password as clear text through POST request!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36899089
>>I just want to send the username and password as clear text through POST request!

Well i already posted a link to an example of that. Just change

>>String data = "width=50&height=100";

to

String data = "username=foo&password=bar";
0
 

Author Comment

by:snajalm
ID: 36899238
I found a couple of cool links that help with making an HTTP POST request and make life a whole lot easier.

http://www.java2s.com/Code/Java/Apache-Common/HttppostmethodExample.htm

http://www.devx.com/Java/Article/17679/0/page/1
http://myjavatools.com/

Regards
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 36899269
>>
http://www.devx.com/Java/Article/17679/0/page/1
http://myjavatools.com/
>>

The above seem to be the same code. Personally i wouldn't use arbitrary code from the web, favouring instead mature APIs such as

>>http://www.java2s.com/Code/Java/Apache-Common/HttppostmethodExample.htm

Having said that, such an API is probably overkill for such a simple requirement (unless you're going to go on to do more complex things, such as cookie management) and you can get along just fine with the generic JRE code i posted without an extra  API
0
 

Author Closing Comment

by:snajalm
ID: 36928665
Thanks heaps for helping through this question!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36930292
No problem. As it happens, i'm working on a reusable https server at the moment and it makes stuff like key management quite simple (using Ant)
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now