基本上我一直在使用這些特定的代碼行很長一段時間,從來沒有遇到過問題。沒有什麼是被感動,但現在我越來越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