【发布时间】:2013-08-21 15:08:22
【问题描述】:
没有postParameters(JSON 字符串,这当然是有效的)一切正常。但是当我添加postParameters 422 响应出现。
postParameters - {"password":"pass","email":"log"} - result of JSONObject.toString()
URL urlToRequest = new URL(SERVICE_URL + path);
urlConnection = (HttpURLConnection) urlToRequest.openConnection();
urlConnection.setConnectTimeout(CONNECTION_TIMEOUT);
urlConnection.setReadTimeout(DATARETRIEVAL_TIMEOUT);
urlConnection.setRequestMethod(requestMethod);
urlConnection.setRequestProperty("Content-Type", "application/json");
urlConnection.setRequestProperty("Accept", "application/json");
if(postParameters != null){
urlConnection.setFixedLengthStreamingMode(postParameters.getBytes().length);
PrintWriter out = new PrintWriter(urlConnection.getOutputStream());
out.print(postParameters);
out.flush();
out.close();
}
int responseCode = urlConnection.getResponseCode();//422
【问题讨论】:
-
你在 postParameters 中发送什么?
-
这家伙以非技术方式解决了同样的问题stackoverflow.com/questions/15093564/…
标签: android json networking httpurlconnection