我有一个问题,我想通过安卓设备登录一个网站。我看过很多关于这个的样本,但它对我不起作用。这是我的代码:
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.example.com/login.php");
httppost.setHeader("Content-Type","text/html");
ArrayList<BasicNameValuePair> pairs = new ArrayList();
pairs.add(new BasicNameValuePair("username", "test1"));
pairs.add(new BasicNameValuePair("password", "pass1"));
try {
UrlEncodedFormEntity p_entity = new UrlEncodedFormEntity(pairs, HTTP.UTF_8);
/** Assign the POST data to the entity */
httppost.setEntity(p_entity);
/** Perform the actual HTTP POST */
HttpResponse response = httpclient.execute(httppost);
TextView txtView = (TextView)findViewById(R.id.txtMessage);
txtView.setText(EntityUtils.toString(response.getEntity()));
} catch (UnsupportedEncodingException uee) {
uee.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
我不明白 new BasicNameValuePair("username", "test1") 。这里的态度是什么.???
<input type="text" name="username" size="25" maxlength="40" value="" class="post" id="autofocus" tabindex="1"/>
<input type="password" name="password" size="25" maxlength="32" class="post" tabindex="2"/>
它只是返回登录页面。它不会将参数传递给 login 。有什么建议么 ?