我用JSON從android發送數據到php。爲此,我使用的代碼如下我的代碼不能用於發送數據到php
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://futuretime.in/reg.php");
httppost.setHeader("content-type", "application/json");
JSONObject dataJson = new JSONObject();
dataJson.put("password", password);
dataJson.put("number", Integer.parseInt("5556"));
StringEntity entity = new StringEntity(dataJson.toString());
httppost.setEntity(entity);
HttpResponse response = httpclient.execute(httppost);
text=response.toString();
當我excuted這我得到一個消息,如:org.apache.http.message.basichttpresponse 4fb06e5e
我應該如何傳遞數據 – user3481084
您需要追加你的數據到網址,在你的情況下你的發送密碼和數字,所以你應該這樣發送 String basicUrl =「http://futuretime.in/reg.php」; String url = basicUrl +「?<你的php文件中的密碼變量名> =」+ <你的密碼> +「&<你的php文件中的變量名> =」+; getUrlData(url); –