473,399 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Post Method in java.net

freddieMaize
I’m using a POST method in java.net. Below are my code snippets.

Expand|Select|Wrap|Line Numbers
  1. String username = "Freddiemaize";
  2. String password = "*******";
  3. String loginDetails = "user_login="+ username +"&user_pass=" + password;
Expand|Select|Wrap|Line Numbers
  1. URL wordpressLogin = new URL( " http://freddiemaize.wordpress.com/wp-login.php /" );
  2. HttpURLConnection HTTP = ( HttpURLConnection ) wordpressLogin.openConnection();
Expand|Select|Wrap|Line Numbers
  1. HTTP.setRequestMethod( "POST" );
  2. HTTP.setRequestProperty( "Content-Length", "" + Integer.toString(loginDetails.getBytes().length ) );
  3. HTTP.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded" );
Expand|Select|Wrap|Line Numbers
  1. DataOutputStream printOut = new DataOutputStream( HTTP.getOutputStream() );
  2. printOut.writeBytes(loginDetails);
Expand|Select|Wrap|Line Numbers
  1. System.out.println("getHeaderFields - "+HTTP.getHeaderFields().toString());
  2. System.out.println("getRequestMethod - "+HTTP.getRequestMethod());
  3. System.out.println("getRequestMethod - "+HTTP.getResponseCode());
  4. System.out.println("getURL - "+HTTP.getURL().toString());
  5. in.close();
However the results are not as expected. Below is my output,
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
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.

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
Dec 19 '08 #1
1 4307
Or atleast any suggestions on what response code would be returned if we ask for a login page via POST method. 200 or a 302 ? generally?

fREDDIE
Dec 22 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: TG | last post by:
Dear PHP Group, I have two forms that are used to collect user information. The first one takes user inputted values such as fullname, city, address etc. I want these values to display in the...
0
by: panayiotis periorellis | last post by:
Hello All, Im trying to pass some parameters to a CGI script from Java. I know how to pass simple parameters but im having trouble passing the radio button. Could someone please have a look at...
2
by: Laurent Thery | last post by:
Given the following example: ============================================ class A { int method (B a) { return 1; } } class B extends A {
2
by: Steve | last post by:
Does anyone know what is wrong with this code or why I might be experiencing this behavior? I have a Java application that submits HTTP POST requests to a servlet (with content in the body of...
8
by: Bill Tschumy | last post by:
First let me state upfront that I'm a Java programmer, not a web developer. Consequently I may be flying a bit wild here... I have scoured the web and usenet for solutions on how to communicate...
3
by: Brian Henry | last post by:
I have two list boxes on my form... lstCanSend and lstRecipients... well then there are two buttons add and remove between them (your basic select and pick listing) which uses java script to move...
3
by: Patrick Fogarty | last post by:
I am programming what is to be a web service client that will use an HTTP-POST to request and retrieve data. The remote server (written in java for what it's worth) requires basic authentication...
4
by: lilyumestar | last post by:
I have project I have to do for class. We have to write 4 different .java files. Project2.java HouseGUI.java House.java HouseSorting.java I already finish House.java and I need to work on...
2
freddieMaize
by: freddieMaize | last post by:
Hi everyone, I'm trying to access a url from java (using java post method). The url is a login page. I then insert values (username and password) to it an try to post that page. Below is my code,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.