我尝试通过 REST API 上传图像。当我尝试连接 HttpURL 时,它会返回 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”。
我无法发现我的错误是什么:(。请帮助我如何解决这个问题。谢谢大家。
最佳答案
HTTP 500 是服务器端错误。我建议您联系负责报告此错误的此服务的人员。
关于java - HttpURLConnection 响应代码返回 500,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28052728/