亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

嘗試通過 PHP POST 方法提交 android 表單數據

嘗試通過 PHP POST 方法提交 android 表單數據

搖曳的薔薇 2021-10-28 09:46:55
我正在嘗試創建一個通過 POST 方法發送信息的表單。public class PostData extends AsyncTask<String, Void, String> {    @Override    protected String doInBackground(String... params) {        try {            HttpClient httpclient = new DefaultHttpClient();            HttpPost httppost = new HttpPost("http://www.yourdomain.com/serverside-script.php");            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);            nameValuePairs.add(new BasicNameValuePair("id", "01"));            nameValuePairs.add(new BasicNameValuePair("message", params[0]));            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));            try {                HttpResponse response = httpclient.execute(httppost);                String op = EntityUtils.toString(response.getEntity(), "UTF-8");//The response you get from your script                return op;            } catch (IOException e) {                e.printStackTrace();            }            //reset the message text field        } catch (IOException e) {            e.printStackTrace();        }        return null;    }    @Override    protected void onPostExecute(String s) {        super.onPostExecute(s);        msgTextField.setText("");        Toast.makeText(getBaseContext(), "Sent", Toast.LENGTH_SHORT).show();    }}但是當我嘗試導入 HttpClient、HttpPost、BaseNameValuePair 等時出現錯誤......import org.apache.http.NameValuePair;import org.apache.http.client.ClientProtocolException;import org.apache.http.client.HttpClient;import org.apache.http.client.entity.UrlEncodedFormEntity;import org.apache.http.client.methods.HttpPost;import org.apache.http.impl.client.DefaultHttpClient;import org.apache.http.message.BasicNameValuePair;請幫忙!!
查看完整描述

2 回答

  • 2 回答
  • 0 關注
  • 147 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號