【发布时间】:2015-06-15 11:44:58
【问题描述】:
我是安卓应用的新手。我想将数据从 android 应用程序发送到 php 页面的要点,但我的代码中出现以下错误
org.apache.http.impl.client.defaulthttpclient 已弃用。
我尝试了很多方法,但还没有成功。
我的机器人是1.2.1.1 (API 22: 5.1.1)。
下面是我的代码。
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("dataOne", "Hello"));
nameValuePairs.add(new BasicNameValuePair("dataTwo", "Android World"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
【问题讨论】: