-4
我想從json格式的數據發送到PHP的web服務。 但我的web服務沒有得到任何迴應。 我試了一下:php沒有從android獲取數據
public void postLatLong (double lat, double lon) throws MalformedURLException {
try {
URL url = new URL("http://server/path/index.php");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoInput(true);
connection.setDoOutput(true);
OutputStream out = connection.getOutputStream();
OutputStreamWriter outwriter = new OutputStreamWriter(out, "UTF-8");
BufferedWriter writer = new BufferedWriter(outwriter);
JSONObject json = new JSONObject();
json.put("lat", lat);
json.put("lon", lon);
Log.d("JSONString",json.toString());
writer.write(json.toString());
writer.flush();
writer.close();
connection.connect();
InputStream in = connection.getInputStream();
InputStreamReader inreader = new InputStreamReader(in, "UTF-8");
BufferedReader reader = new BufferedReader(inreader);
Log.d("Response",reader.readLine());
reader.close();
} catch (IOException e) {
Log.d("posting Error", e.getMessage());
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.d("JSONException", e.getMessage());
}
}
我收到respons。 沒有顯示錯誤日誌,json沒問題,我可以在日誌中看到它。但是,當我檢查webservice日誌時,POST請求中沒有任何內容。
請在您的問題中包含錯誤消息/堆棧跟蹤/事件日誌信息。 –