public static Bitmap getImage(String address) throws Exception {
Bitmap imgmap = null;
InputStream is = null;
URL url = new URL(address);
HttpURLC
When you create an instance of HttpURLConnection it defaults to the request method GET so there is no need to call setRequestMethod in this instance.
This link contains some fantastic detail about HTTP connections and how to use them.
Experienced same, find out the IDE is watching a field of the connection which I have added to debug, then cause the connection get established before other code run like set properties.
So if you want to get some "properties" before connection is ready during debug, you will get this error
This is happening because you're connecting before setting the request method
A suggest you try this:
conn.setRequestMethod("GET");
conn.connect);
conn.setConnectTimeout(5000);
is = conn.getInputStream();
byte[] imgbytes = StreamTool.getBytes(is);
Thats because the function setRequestMethod()
has to be called before the connection is made.
Check this link
http://developer.android.com/reference/java/net/HttpURLConnection.html#setRequestMethod(java.lang.String)
So better call it before openConnection(). Or dont call it at all.
I know it is completely nonsense. But it happens for me in debug mode when I put break point on this line.
con.setRequestMethod()
As soon as I removed the break point, the error has gone!