asp.NET post from java
Somehow the normal httpPost does not insert the values that I send.
here is the html form:
<form id="LoginForm" name="LoginForm" method="post" action="Login.aspx?__ufps=104203&ReturnUrl=%2fsyspower3%2fmobile%2fdefault.aspx&AspxAutoDetectCookieSupport=1">
<input type="hidden" name="__VIEWSTATE" value="/wEXAQUDX19QD2QPBvUTF2XiFM6IZg==">
<input type="hidden" name="__EVENTTARGET" value="">
<i开发者_开发百科nput type="hidden" name="__EVENTARGUMENT" value="">
<br>
<b>Username:</b><br>
<input name="ctl00$tbUsername"/><br>
<b>Password:</b><br>
<input name="ctl00$tbPwd" type="password"/><br>
<input type="checkbox" name="ctl00$chkRememberLogin" value="0" checked>Remember Me<br>
<input name="ctl00$cmdLogin" type="submit" value="Login"/>
<input name="ctl00$cmdForgetMe" type="submit" value="Forget Me"/>
</form>
and this is what I am trying to do in java:
HttpPost httppost2 = new HttpPost(
"www.website.com/Login.aspx?ReturnUrl=%2fsyspower3%2fmobile%2fdefault.aspx&AspxAutoDetectCookieSupport=1");
List<NameValuePair> nameValuePairs2 = new ArrayList<NameValuePair>(4);
nameValuePairs2.add(new BasicNameValuePair("ctl00$tbUsername", "username"));
nameValuePairs2
.add(new BasicNameValuePair("ctl00$tbPwd", "password"));
nameValuePairs2.add(new BasicNameValuePair("ctl00$chkRememberLogin", "0"));
nameValuePairs2.add(new BasicNameValuePair("ctl00$cmdLogin", "Login"));
nameValuePairs2.add(new BasicNameValuePair("ctl00$cmdForgetMe", "Forget Me"));
httppost2.setEntity(new UrlEncodedFormEntity(nameValuePairs2));
response = httpclient.execute(httppost2);
String responseBody4 = EntityUtils.toString(response.getEntity());
System.out.println(responseBody4);
But the form does not change, I mean there are no values in the input as well.. Maybe that is not the way to do it. What could be the other way to accomplish form submission?
EDIT: As i understood, do I also must post __VIEWSTATE, __EEVENTTARGET, EVENTARGUMENT values When I check the Post values from the wireshark, they are identical to the once I post from the application... so it is a little bit confusing. I bet it is the VIEWSTATE value, that I must first get from the service and then reuse it when doing a Post
please add the url params in the NameValuePair
object (?ReturnUrl=%2fsyspower3%2fmobile%2fdefault.aspx&AspxAutoDetectCookieSupport=1");
), also ensure that you specify the protocol being used http://
or https://
精彩评论