lez60
asked on
POST from HttpsURLConnection
I am trying to create web client for form-based logging .
here is the piece of code I am using.
All values I am getting by parsing start up form.
When looking at Post request in IEWatch one line is different:
(Method-Line) POST /c/a/WirelessLogIn HTTP/1.1
I am using just connection.setRequestMetho d("POST"); without any parameters
I am not sure if this makes any difference.
Here is what I am posting:
String body ="USERID="+v_account+"&PAS SWORD="+v_ pin
+"&login=Login&pagehandler =PHWireles sLogIn&DV_ DATA="+v_d ata+"&USER GROUP=ACCT &COMPANY=A BCD";
url = new URL(t_url+body);
connection = (HttpsURLConnection)url.op enConnecti on();
connection.setDoOutput(tru e);
connection.setDoInput(true );
connection.setUseCaches(fa lse);
connection.setDefaultUseCa ches(false );
connection.setFollowRedire cts(false) ;
connection.setInstanceFoll owRedirect s(false);
connection.setRequestMetho d("POST");
//connection.setRequestPro perty("Acc ept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-fl ash, application/vnd.ms-excel, application/msword, */*");
connection.setRequestPrope rty("Accep t", "*/*");
connection.setRequestPrope rty("Refer er", "https://www.abcd.com/c/a/WirelessLogInForm");
connection.setRequestPrope rty("Accep t-Language " , "en-us");
connection.setRequestPrope rty("Accep t-Encoding ", "gzip, deflate");
connection.setRequestPrope rty("Conte nt-Type" , "application/x-www-form-ur lencoded") ;
connection.setRequestPrope rty("User- Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)");
connection.setRequestPrope rty("Host" , "www.abcd.com");
// connection.setRequestPrope rty("Conte nt-Length" ,"120");
connection.setRequestPrope rty("Conne ction", "Keep-Alive");
connection.setRequestPrope rty("Cache -Control", "no-cache");
connection.setRequestPrope rty("Cooki e", cookie);
connection.connect();
The response is :
<HTML>
<TITLE>Page Unavailable</TITLE><BODY>
/html/errors/404.html is unavailable, please contact system administractor.
</BODY>
</HTML>
As you can see I've commented out one line // connection.setRequestPrope rty("Conte nt-Length" ,"120");
because with this line the sessin hangs and I am getting no response at all .
How to solve this issue ???
Thx
here is the piece of code I am using.
All values I am getting by parsing start up form.
When looking at Post request in IEWatch one line is different:
(Method-Line) POST /c/a/WirelessLogIn HTTP/1.1
I am using just connection.setRequestMetho
I am not sure if this makes any difference.
Here is what I am posting:
String body ="USERID="+v_account+"&PAS
+"&login=Login&pagehandler
url = new URL(t_url+body);
connection = (HttpsURLConnection)url.op
connection.setDoOutput(tru
connection.setDoInput(true
connection.setUseCaches(fa
connection.setDefaultUseCa
connection.setFollowRedire
connection.setInstanceFoll
connection.setRequestMetho
//connection.setRequestPro
connection.setRequestPrope
connection.setRequestPrope
connection.setRequestPrope
connection.setRequestPrope
connection.setRequestPrope
connection.setRequestPrope
connection.setRequestPrope
// connection.setRequestPrope
connection.setRequestPrope
connection.setRequestPrope
connection.setRequestPrope
connection.connect();
The response is :
<HTML>
<TITLE>Page Unavailable</TITLE><BODY>
/html/errors/404.html is unavailable, please contact system administractor.
</BODY>
</HTML>
As you can see I've commented out one line // connection.setRequestPrope
because with this line the sessin hangs and I am getting no response at all .
How to solve this issue ???
Thx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
no worries :)
ASKER
somtimes I was using GET method to login, and it worked, but in this situation it had to bePOST .
Great, I am really approciated