Im trying to download an image from a specific website.
Actually, my code is up and running in production for months, but it's not able to download imagens from this specific website
The image URL I need to download is this one: (for instance) http://static7.kabum.com.br/produtos/fotos/64297/64297_index_g.jpg
The codes I tried so far:
Method 1 -> (failed)
string url = "http://static7.kabum.com.br/produtos/fotos/64297/64297_index_g.jpg";
var request = (HttpWebRequest)WebRequest.Create(url);
request.Timeout = (timeout == 0 ? 30 : timeout) * 1000;
request.KeepAlive = false;
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36";
var response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
const int BUFFER_SIZE = 16 * 1024;
var buffer = new byte[BUFFER_SIZE];
// if the remote file was found, download it
using (Stream inputStream = response.GetResponseStream())
using (Stream outputStream = File.Create(fileName, BUFFER_SIZE))
{
int bytesRead;
do
{
bytesRead = inputStream.Read(buffer, 0, buffer.Length);
outputStream.Write(buffer, 0, bytesRead);
} while (bytesRead != 0);
}
}
Method 2 -> (also failed)
[..]
using(Image webImage = Image.FromStream(response.GetResponseStream()))
{
webImage.Save(fileName);
}
[..]
Both methods fail with the following exception
“Parameter not valid” exception loading System.Drawing.Image
StackTrace = " em System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData) in System.Drawing.Image.FromStream(Stream stream) in MonitorLib.Helper.RequestPageHelper.RequestDowloadPage(Boolean proxy, Strin...
I guess the image data is incomplete or compacted, but the URL Works fine on any browser
any thoughts? thanks a lot friends