Solved

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

Posted on 2011-09-29
15
444 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Introduction and Prerequisites This article describes methods for detecting whether a client browser accepts and returns HTTP cookies and whether the client browser runs JavaScript.  Most client browsers will, by default, be configured to use cooki…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

632 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