Results 1 to 3 of 3
Thread: Post Method in java.net
- 12-22-2008, 06:00 AM #1
Post Method in java.net
I’m using a POST method in java.net. Below are my code snippets.
Java Code:String username = "Freddiemaize"; String password = "*******"; String loginDetails = "user_login="+ username +"&user_pass=" + password;
Java Code:URL wordpressLogin = new URL( " http://freddiemaize.wordpress.com/wp-login.php /" ); HttpURLConnection HTTP = ( HttpURLConnection ) wordpressLogin.openConnection();
Java Code:HTTP.setRequestMethod( "POST" ); HTTP.setRequestProperty( "Content-Length", "" + Integer.toString(loginDetails.getBytes().length ) ); HTTP.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded" );
Java Code:DataOutputStream printOut = new DataOutputStream( HTTP.getOutputStream() ); printOut.writeBytes(loginDetails);
However the results are not as expected. Below is my output,Java Code:System.out.println("getHeaderFields - "+HTTP.getHeaderFields().toString()); System.out.println("getRequestMethod - "+HTTP.getRequestMethod()); System.out.println("getRequestMethod - "+HTTP.getResponseCode()); System.out.println("getURL - "+HTTP.getURL().toString()); in.close();
Well, I expect a 302 response code and the method to be POST and the url to be http*://freddiemaize.wordpress.com/wp-admin/ which is my landing page.getRequestMethod - GET
getRequestMethod - 200
getURL - http*://freddiemaize.wordpress.com/wp-login.php?action=auth&redirect_to=
http%3A%2F%2Ffreddiemaize.wordpress.com%2Fwp-admin%2F
My doubt is, is my expectation wrong or my expectation is correct but there is a bug in my code. Please advice. Thank you very much.
Freddie
- 02-15-2009, 08:49 PM #2
Member
- Join Date
- Feb 2009
- Location
- United Kingdom
- Posts
- 1
- Rep Power
- 0
Мировой финансовый кризис
В нынешней ситуации большинство тем отходят на второй план. Интересно, как мы будем жить, если доллар рухнет?
- 02-23-2009, 02:59 AM #3
Member
- Join Date
- Feb 2009
- Posts
- 1
- Rep Power
- 0
Similar Threads
-
First post ever
By pbpersson in forum IntroductionsReplies: 4Last Post: 08-16-2008, 05:30 AM -
First post as per request
By happyknappy in forum IntroductionsReplies: 3Last Post: 07-30-2008, 01:33 AM -
The first post and first question
By m_kaleia in forum New To JavaReplies: 8Last Post: 07-19-2008, 06:27 PM -
post info to a webpage
By kmp in forum NetworkingReplies: 1Last Post: 03-22-2008, 02:20 AM -
How to post HTTPS request from java client to server
By Desai in forum NetworkingReplies: 1Last Post: 07-14-2007, 05:15 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks