How to enter to .aspx page by http connection using http POST request

F

farazkazmi

I m facing dificulty with http "POST" request.

i need to login to a website " https://www.orkut.com "
it requires username and password.

i dont know how to enter username and password so that i can access the
page by myjava class.

i m using this code gor gettinh request:

public static String GetRequest() throws IOException {

String urlString = "https://www.orkut.com";
DataInputStream dis = null;
StringBuffer message = new StringBuffer();
String outputMessage = new String();
URL url = new URL(urlString);
HttpURLConnection httpConnection =
(HttpURLConnection) url.openConnection();
httpConnection.setRequestMethod("GET");
httpConnection.setDoInput(true);
Properties props = System.getProperties();
props.put("http.proxyHost", "SERVER");
props.put("http.proxyPort", "8080");
httpConnection.connect();

System.out.println(httpConnection.getResponseCode());

dis = new DataInputStream(httpConnection.getInputStream());
int ch;
while ((ch = dis.read()) != -1) {
message.append((char) ch);
}
outputMessage = message.toString();
//System.out.println(outputMessage);
httpConnection.disconnect();
return outputMessage;
}

now if i change request method to POST , then plz tell me how can i
enter username and password by my java code.

fhkazmi
 
R

Raymond DeCampo

now if i change request method to POST , then plz tell me how can i
enter username and password by my java code.

Look into the HTTP client library from Apache Jakarta.

Ray
 
T

Tor Iver Wilhelmsen

i need to login to a website " https://www.orkut.com "
it requires username and password.

i dont know how to enter username and password so that i can access the
page by myjava class.

If you call

httpConnection.setAllowUserInteraction(true);

you should be prompted for username and password if they use BASIC or
DIGEST HTTP authentication. I don't see anywhere else that you provide
the username or password.

If they are parameters but you left them out here, you pass parameters
in the request body when using POST. Get the output stream and write e.g.

username=user&password=password

there. To help the server a little, you should also set the
Content-Length request field to the length of that body.
 
F

farazkazmi

If you call

httpConnection.setAllowUserInteraction(true);

you should be prompted for username and password if they use BASIC or
DIGEST HTTP authentication. I don't see anywhere else that you provide
the username or password.

If they are parameters but you left them out here, you pass parameters
in the request body when using POST. Get the output stream and write e.g.

username=user&password=password
...
After some research i found that, i can also login by this url through
browser.
https://www.orkut.com/Login.aspx?&u=username&p=password.

i tried allow user interaction but it didnt work.

also m confused about the Content Length , if it is
String info = u=username&p=password then
httpConnection.setRequestproperty("CONTENT-LENGTH","info.Length()");

is it right?.

plz tell me ,
i tried with the above link with username and password but it retrs the
same URL page.

any idea?

plz tell me..
 
F

farazkazmi

i found 1 problem that the returend page has the follwing message
" Please enable cookies in your browser to login to orkut"

plz tell me how can i deal with this problem
 
T

Tor Iver Wilhelmsen

plz tell me how can i deal with this problem

You need to detect (keep) the Set-Cookie header value you get in the
response when logging in, and send it back on every further request.
Do a Google search for the HTTP cookie spec.
 
T

Tor Iver Wilhelmsen

httpConnection.setRequestproperty("CONTENT-LENGTH","info.Length()");

Almost:

httpConnection.setRequestproperty("CONTENT-LENGTH",String.valueOf(info.length()));

And you only do this if you use a POST type request - you apparently
use a GET since you pass the parameters in the URL.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top