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.setRequestMethod("POST");   without any parameters
I am not sure  if this makes any difference.

Here is what  I am posting:
      String body    ="USERID="+v_account+"&PASSWORD="+v_pin
                     +"&login=Login&pagehandler=PHWirelessLogIn&DV_DATA="+v_data+"&USERGROUP=ACCT&COMPANY=ABCD";
      url = new URL(t_url+body);
      connection = (HttpsURLConnection)url.openConnection();
      connection.setDoOutput(true);
      connection.setDoInput(true);
      connection.setUseCaches(false);
      connection.setDefaultUseCaches(false);
      connection.setFollowRedirects(false);
      connection.setInstanceFollowRedirects(false);
      connection.setRequestMethod("POST");
      //connection.setRequestProperty("Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/msword, */*");
      connection.setRequestProperty("Accept", "*/*");
      connection.setRequestProperty("Referer", "https://www.abcd.com/c/a/WirelessLogInForm");
      connection.setRequestProperty("Accept-Language" , "en-us");
      connection.setRequestProperty("Accept-Encoding", "gzip, deflate");
      connection.setRequestProperty("Content-Type" , "application/x-www-form-urlencoded") ;
      connection.setRequestProperty("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.setRequestProperty("Host", "www.abcd.com");
     // connection.setRequestProperty("Content-Length","120");    
      connection.setRequestProperty("Connection", "Keep-Alive");
      connection.setRequestProperty("Cache-Control", "no-cache");
      connection.setRequestProperty("Cookie", 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.setRequestProperty("Content-Length","120");  
because with this line the sessin hangs and I am getting no response at all .
How to solve this issue ???
Thx
   


lez60Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
>     String body    ="USERID="+v_account+"&PASSWORD="+v_pin
>                     +"&login=Login&pagehandler=PHWirelessLogIn&DV_DATA="+v_data+"&USERGROUP=ACCT&COMPANY=ABCD";

your passing the parameters as a GET.
For a post you need to instead write them to the connections output sytream

http://javaalmanac.com/egs/java.net/Post.html

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lez60Author Commented:
Yes !!!  It works , Thanks !!. I've seen this example before but it looks like not quite got it before. POST and GET is a little bit confusing,
somtimes I was using GET method to login, and it worked, but in this situation it had to bePOST .

Great, I am really approciated

 
Mick BarryJava DeveloperCommented:
no worries :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.