没有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