我有以下代码,通过它我无法使用PUT请求向我的服务器发送json字符串。服务器有REST api。
try {
m_url = new URL(URL);
m_conn = (HttpURLConnection) m_url.openConnection();
URL url = m_conn.getURL();
Log.d("Sending to --->", url.toString());
JSONObject jsonObject = new JSONObject();
JSONObject jsondtObj = new JSONObject();
JSONObject jsonitObj = new JSONObject();
JSONArray jsonArray = new JSONArray();
jsonObject.put("addr_locality_o", "White plains");
jsonArray.put(jsonObject);
jsondtObj.put("data", jsonArray);
jsonitObj.put("template",jsondtObj);
Log.d("sending JSON: " , jsonitObj.toString());
String sessionID = m_qeeAppCtrl.getSessTok();
Log.d("session Token: " , sessionID);
m_conn.setDoOutput(true);
m_conn.setRequestMethod("PUT");
m_conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
m_conn.setRequestProperty("Cookie", sessionID);
OutputStream out = m_conn.getOutputStream();
out.write(jsonitObj.toString().getBytes("UTF-8"));
out.close();
m_conn.getInputStream();
retc = m_conn.getResponseCode();
Log.d("Response : ", String.valueOf(retc));
if (retc == 200) {
Log.d("NO Exception: ", "");
}
} catch (MalformedURLException e) {
e.printStackTrace();
Log.d("Exception: ", e.getMessage());
} catch (IOException e) {
e.printStackTrace();
Log.d("Exception: ", e.getMessage());
} catch (Exception e) {
Log.d("Exception: ", e.getMessage());
}finally {
return retc;
}
我在服务器日志中没有任何东西,同时,我在logcat窗口中没有任何异常,也没有在日志文件中打印响应代码。我查看了其他论坛,但即使在应用所有解决方案(如UTf-8编码)之后,仍然没有线索:(
请帮忙
由于