2013-08-21 40 views
1

沒有postParameters(JSON字符串,這當然是有效的)一切工作正常。但是當我添加postParameters 422響應出現。HttpURLConnection返回由於JSON 0122代碼

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 
+0

你在postParameters發送? – Shrikant

+0

我已更新帖子。 – eleven

+1

這個人用非技術方式解決了同樣的問題http://stackoverflow.com/questions/15093564/android-problems-parsing-json-returned-by-a-422-response – Shrikant

回答

相關問題