close

try {
HttpClient client = new DefaultHttpClient();
URI website = new URI("網路URL"); //指定URL
//指定POST模式
HttpPost request = new HttpPost();

//POST傳值必須將key、值加入List<NameValuePair>
List<NameValuePair> parmas = new ArrayList<NameValuePair>();

//逐一增加POST所需的Key、值
parmas.add(new BasicNameValuePair("ac", "變數值"));
parmas.add(new BasicNameValuePair("pwd","變數值"));

//宣告UrlEncodedFormEntity來編碼POST,指定使用UTF-8
UrlEncodedFormEntity env = new UrlEncodedFormEntity(parmas, HTTP.UTF_8);
request.setURI(website);

//設定POST的List
request.setEntity(env);
HttpResponse response = client.execute(request);
HttpEntity resEntity = response.getEntity();

//返回的值
if (resEntity != null) {
String msg = EntityUtils.toString(resEntity);
tv1.setText(msg);
} else {
String msg = "無資料";
}
}catch (Exception e) {

e.printStackTrace();
}

arrow
arrow
    全站熱搜

    stockwfj3 發表在 痞客邦 留言(0) 人氣()