1

postParameters(もちろん有効な JSON 文字列) がなければ、すべて正常に動作します。しかし、追加するとpostParameters422 応答が表示されます。

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
4

1 に答える 1