=====已更新========
实际上下面的代码很好,我的问题是在服务器端。
=====已更新========
下面是我的代码,我正在使用 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();
最佳答案
关于java - Android Post 请求未在服务器上发布任何数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35077930/