lundi 7 décembre 2015

get image from URL - not working

I have tried to implement the solution from Load an image from a url into a PictureBox

The code that works, to solve the above question is:

var request = WebRequest.Create("http://ift.tt/1BUMu3A");

using (var response = request.GetResponse())
using (var stream = response.GetResponseStream())
{
    Image img =  Bitmap.FromStream(stream);
}

Now, I try replace that URL with mine:

var request = WebRequest.Create("http://ift.tt/1XQGXIV");

using (var response = request.GetResponse())
using (var stream = response.GetResponseStream())
{
    Image img =  Bitmap.FromStream(stream); //error here
}

But I get the following error: parameter is not valid.

here is the header response: enter image description here here is the HTML of: http://ift.tt/1XQGXIV

<!DOCTYPE html>
<html>
<head>
    <meta content="width=device-width, minimum-scale=0.1" name="viewport">
    <title>GetFile (419×600)</title>
</head>
<body style="margin: 0px;">
    <img height="150" src=
    "http://ift.tt/1XQGXIV"
    style="-webkit-user-select: none; cursor: zoom-in;" width="104">
</body>
</html>

I have a feeling, that comparing the two URL's, mine has an additional HTML response: Content-Encoding:gzip

Thanks Dan

Aucun commentaire:

Enregistrer un commentaire