从研究中我发现,我可以使用HttpPost将信息发送到服务器,所以我有。
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("https://portal.sibt.nsw.edu.au/Default.asp");
我有两个EditText字段来保存userId和密码,还有一个用于登录的按钮。
EditText id ;
EditText pword ;
Button logIn ;
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(2);
nameValuePair.add(new BasicNameValuePair("UserID", id.getText().toString()));
nameValuePair.add(new BasicNameValuePair("Password", pword.getText().toString()));
post.setEntity(new UrlEncodedFormEntity(nameValuePair));//already inside a try/catch() block
new getResponse().execute()
// in AsyncTask
public abstract class getResponse extends AsyncTask<Void, Void, Void>{
public String doInBackground(){
try {
HttpResonse response = client.execute(post);
String responseContent = EntityUtils.toString(response.getEntity());
Log.d("response to string", responseContent);
}/...
现在在LogCat中我看到了这个“https://portal.sibt.nsw.edu.au/Default.asp”的html,但是,当检查实体时 的System.out.println(post.getEntity()); 我得到“org.apache.http.client.entity.UrlEncodedFormEntity@41237c10”但是我没有得到我应该回复的页面,这是登录后的页面,而是我得到了“post”的HTML。我做错了什么。
注意:在4.1.2中编译
答案 0 :(得分:0)
您需要获取内容以使用该消息:
InputStream in = entity.getContent();
然后你可以阅读你的InputStream