[英]How to send request(String data) from android to PHP server localhost and receive response result form server PHP
[英]How to send an array of data from Android to php server?
對於單對值,我使用了:
datas.add(new BasicNameValuePair("latitude", Double.toString(lastKnownLocation.getLatitude())));
然后使用HttpClient
將其發送到服務器:
HttpClient httpclient = CustomHttpClient.getHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(datas));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
input = entity.getContent();
在服務器端,我按以下方式提取此信息:
$latitude = (_POST['latitude']);
但對於我自己的類型的數組,表示Place
用3個字段:
class Place {
int id;
String name;
String address;
}
如何將這些信息發送到我的php腳本? 在我的PHP中,如何提取此JSON數組?
有無數種傳輸數據的方法,但是更常見的數據交換方法之一是通過JSON。
有關如何操作的信息,請參見此問題 。 簡而言之,您
有關如何在服務器端解釋JSON,請參見qklxtlx的響應。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.