Android POST-JSON的问题
我正在尝试向JSON文件发送一个http POST请求,其中包含1个int和2个list[]。服务器获取我的请求,但json始终为空。我的代码有什么问题??当我发布HashMap login+pass时,它工作得很好,但使用json时出现了一些问题Android POST-JSON的问题,android,json,http-post,Android,Json,Http Post,我正在尝试向JSON文件发送一个http POST请求,其中包含1个int和2个list[]。服务器获取我的请求,但json始终为空。我的代码有什么问题??当我发布HashMap login+pass时,它工作得很好,但使用json时出现了一些问题 try { JSONObject jsonParam = new JSONObject(); jsonParam.put("categories_1", y);
try {
JSONObject jsonParam = new JSONObject();
jsonParam.put("categories_1", y);
jsonParam.put("categories_1", x);
jsonParam.put("price", 3000);
url = new URL(adress);
conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(15000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(os, "UTF-8"));
writer.write(jsonParam.toString());
writer.flush();
writer.close();
os.close();
int responseCode=conn.getResponseCode();
if (responseCode == HttpsURLConnection.HTTP_OK) {
String line = null;
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line = br.readLine()) != null) {
buffer.append(line);
}
resultJson = buffer.toString();
Log.d(LOG_TAG, "response - " + response);
Log.d(LOG_TAG, "Good response - " + responseCode);
}
else {
response="";
Log.d(LOG_TAG, "bad responce - " + responseCode);
}
在此处共享服务器日志/代码或“hashmap”请求以获得具体答案可能很有用。在此处共享服务器日志/代码或“hashmap”请求以获得具体答案可能很有用。