1

Without postParameters (JSON string, which is of course valid) everything works fine. But when I add postParameters 422 response appears.

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
eleven
  • 6,779
  • 2
  • 32
  • 52

1 Answers1

0

Rebooting Android device helped. The same problem with PC: Android, Problems parsing json returned by a 422 response

Thanks to Shrikant

Community
  • 1
  • 1
eleven
  • 6,779
  • 2
  • 32
  • 52