0
我嘗試通過REST API上傳圖像。當我嘗試使用HttpURL連接時,它會返回500響應代碼。我還嘗試通過很多方式解決問題,以免找出問題。我的代碼HttpURLConnection ResponseCode return 500
URL url = new URL(urlLink);
connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type","multipart/form-data;boundary=----------V2ymHFg03ehbqgZCaKO6jy");
connection.setRequestProperty("DocumentId", ""+ AppConstant.DocumentId);
connection.setRequestProperty("Host", "www.cashsheet.com");
connection.setRequestProperty("Authorization", au);
connection.setRequestProperty("UserId", "" + AppConstant.UserId);
int responseCode = connection.getResponseCode();
Log.w("responseCode", "are"+responseCode);
try {
InputStream inputStream = connection.getInputStream();
} catch (IOException ioe) {
connection.disconnect();
Log.w("IOException", "are"+ioe.getMessage());
// If HTTP response code '401' is returned then try to resume
// the expired
// session on the reporting server by obtaining a new HTTP URL
// Connection.
if (connection.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) {
//throw new ClusterException(
// "The access to the requested resource was denied; the request may have been made without authorization credentials.");
}
// If response code other than '401' is returned then propagate
// the IOException to the next level.
else {
//throw new ClusterException(ioe.getMessage());
}
}
所有時間它重新運行響應代碼500並顯示urlLink上的錯誤; urlLink =「http://www.cashsheet.com/api/upload」。
我不能夠趕上什麼是我的錯誤:(請幫助我怎樣才能解決這個issues.Thanks所有。
你好@布魯諾可能是你說的correct.But上傳正確的圖像。我嘗試上傳這個Android.Id它是服務器錯誤,然後iOS無法上傳圖片。 – Prosanto 2015-01-21 20:32:44