基本上我一直在使用这些特定的代码行很长一段时间,从来没有遇到过问题。没有什么是被感动,但现在我越来越HTTP请求 - 已连接
IllegalStateException异常 - 已经连接
正是之后我设置conn.setUsesCaches(false)
public void PutImageToS3(String signedUrl, Bitmap image) throws WampNetworkException, IOException {
URL url = new URL(signedUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.getDoOutput();
conn.setUseCaches(false);
conn.setRequestMethod("PUT");
conn.addRequestProperty("Content-Type", "image/jpeg");
conn.addRequestProperty("Connection", "close");
OutputStream out = new BufferedOutputStream(conn.getOutputStream());
image.compress(Bitmap.CompressFormat.JPEG, 100, out);
if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
throw new IOException("Failed to upload image to S3: "
+ conn.getResponseCode() + conn.getResponseMessage() + "\r\n");
}
out.flush();
out.close();
conn.disconnect();
}
在发布问题时,您应始终共享打印堆栈跟踪。 – Rajesh