Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-09-29
15
Medium Priority
?
446 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

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