我已经看了好几天了,仍然无法解决。也许有一些推荐的阅读可以帮助我提高我的基础理解并解决我错过的问题。
机器人:
HttpClient httpClient = new DefaultHttpClient();
CookieStore cookieStore = new BasicCookieStore();
HttpContext context = new BasicHttpContext();
context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
HttpPost httpPost = new HttpPost("http://192.168.1.11:56050/Account/LoginNonWeb.aspx");
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(2);
nameValuePair.add(new BasicNameValuePair("email", mEmail));
nameValuePair.add(new BasicNameValuePair("password", mPassword));
try {
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(nameValuePair, HTTP.UTF_8);
entity.setContentType("application/x-www-form-urlencoded");
httpPost.setEntity(entity);
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
try {
HttpResponse response = httpClient.execute(httpPost, context);
...
}
ASP.Net:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) //check if the webpage is loaded for the first time.
{
System.Collections.Specialized.NameValueCollection postedValues = Request.Form;
foreach (string key in postedValues)
{
var value = postedValues[key];
value = postedValues[key];
}
String loginEmail = postedValues["email"];
String loginPassword = postedValues["password"];
}
}
页面加载Request.Form
时始终为空。随着帖子和实体的内容类型为application/x-www-form-urlencoded
,我期待它被填充。