=====的更新 ======
实际上下面的代码很好,我的问题是在服务器端
=====的更新 ======
以下是我的代码,我使用HttpURLConnection
但无法将JSON
数据发送到服务器。
请提前帮助我
JSONObject jo = new JSONObject();
jo.put("ID", "25")
Log.e("test", jo.toString());
url = new URL(URL);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
//Send request
DataOutputStream wr = new DataOutputStream(
connection.getOutputStream());
wr.writeBytes(jo.toString());
wr.flush();
wr.close();
//Get Response
InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
StringBuffer sb = new StringBuffer();
int chr;
while ((chr = is.read()) != -1) {
sb.append((char) chr);
}
line = sb.toString();
Log.e("json_temp", line);
rd.close();