Last post Mar 18, 2010 02:30 AM by Cheezy
Mar 17, 2010 12:40 AM|tiramisung|LINK
Hi, I had write a code about get a picture from url and save as bitmap. However, there was a problem in HttpWebResponse. It didn't run the code start from HttpWebResponse.Then my whole website die there. May I know what is the problem and how to solve it?
// create a web request to the url of the image
System.Net.HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(URL);
// set the method to GET to get the image
myRequest.Method = "GET";
// get the response from the webpage
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
// create a bitmap from the stream of the response
Bitmap bmp = new Bitmap(myResponse.GetResponseStream());
// close off the stream and the response
// return the Bitmap of the image
Mar 17, 2010 12:56 AM|Cheezy|LINK
Mar 17, 2010 12:57 AM|Binary_Fiddle|LINK
Your code looks fine.
Can you please check if the URL u are using is returning you an image
You can check this by running the url in a browser.
In case you are not getting an image or the response in very slow then either your URL is incorrect or there is some problem with the server.
Mar 17, 2010 01:05 AM|tiramisung|LINK
for sure, my url can return image truely. Just i dont know why it didn't run start from the line HttpWebResponse. Besides, last time i test in IE7 , it works fine. Now i test it in IE8, then this problem occur...Can anyone help me?
Mar 17, 2010 01:09 AM|Cheezy|LINK
had you tried my suggested code? essentially, Close() only closes the connection, but doesnt end the request. End() does that for you.
Mar 17, 2010 02:05 AM|tiramisung|LINK
There is no End() in myRespond....
Mar 17, 2010 02:30 AM|Cheezy|LINK
silly me, lol. got to hit the bed now. must be tired :p. I'll try to reply tomorrow, if this is still open.
Mar 17, 2010 03:18 AM|tiramisung|LINK
Not silly la... at least got give me some idea..
Here, i want to know will it relate to my proxy setting? Because of proxy setting different , so it affect the HttpWebResponse? Because last time i can run it successfully, my internet setting did not tick the proxy server there, only tick the automatic
detect setting. Now because of some internet setting, i had tick the proxy server there and set the address and port.
Is it because of this reason make the HttpWebResponse timeout ?
Mar 18, 2010 02:30 AM|Cheezy|LINK
hi, you said, its hanging, right? does it goes into error for quite sometime? if it does, whats the exact error message. you mentioned about the proxy settings also, had you tried tried debugging and catching the error if its from the request or response?
you might wanna explore the HttpWebRequest's Proxy to try and solve the problem.