0

調査の結果、HttpPost を使用してサーバーに情報を送信できることがわかりました。

HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("https://portal.sibt.nsw.edu.au/Default.asp");

userId とパスワードを保持する 2 つの EditText フィールドと、ログイン用のボタンがあります。

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」を取得しますが、ログイン後のページであるはずの応答ページを取得できず、代わりに「投稿」のHTMLを取得します。私は何を間違っていますか。

注: 4.1.2 でのコンパイル

4

1 に答える 1

0

メッセージを消費するには、コンテンツを取得する必要があります。

InputStream in = entity.getContent();

次に、InputStreamを読み取ることができます

于 2013-02-16T11:49:23.383 に答える