我正在写这篇文章,因为 MrZander 的答案突然出现了......基于@MrZander 的答案,这里有一个例子。如果这可行,请将他的答案标记为已接受。
public void postData() throws ClientProtocolException, IOException, Exception {
String key = "https://www.itrack.somee.com/post.aspx";
//URI uri=new URI(key);
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(key);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
nameValuePairs.add(new BasicNameValuePair("id", "10"));
nameValuePairs.add(new BasicNameValuePair("long", "123"));
nameValuePairs.add(new BasicNameValuePair("lat", "123"));
nameValuePairs.add(new BasicNameValuePair("alt", "123"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
Toast.makeText(this, "here", Toast.LENGTH_LONG).show();
HttpResponse response = httpclient.execute(httppost);
Toast.makeText(this,"mm"+response.toString(), Toast.LENGTH_LONG).show();
}
或者更好的是,我相信您可能正在寻找这样的东西?:
public void postData(int id, double lat, double lng, double alt) throws ClientProtocolException, IOException, Exception {
String key = "https://www.itrack.somee.com/post.aspx";
//URI uri=new URI(key);
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(key);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
nameValuePairs.add(new BasicNameValuePair("id", "" + id));
nameValuePairs.add(new BasicNameValuePair("long", String.valueOf(lat));
nameValuePairs.add(new BasicNameValuePair("lat", String.valueOf(lng));
nameValuePairs.add(new BasicNameValuePair("alt", String.valueOf(alt)));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
Toast.makeText(this, "here", Toast.LENGTH_LONG).show();
HttpResponse response = httpclient.execute(httppost);
Toast.makeText(this,"mm"+response.toString(), Toast.LENGTH_LONG).show();
}