I have a windows application that gets URL and download .jpeg
file. For some urls the ContentLength
property is -1, therefore it throws exception.
Here is my code:
var url = new Uri(sUrlToReadFileFrom[i]);
_request = (HttpWebRequest)WebRequest.Create(url);
var response = (System.Net.WebResponse)_request.GetResponse();
_response = response;
_response.Close();
and Here is the url: http://photos.autonexus.com/imager/115-005-CA/P2GTPI4AB9/640/10132013133959/1FAHP0HA3AR373228_1.jpg and here is some information about my http request:
Headers = {Transfer-Encoding: chunked
Connection: keep-alive
Content-Disposition: inline; filename="phpThumb_generated_thumbnail.jpeg"
Content-Type: image/jpeg
Date: Wed, 12 Nov 2014 00:31:29 GMT
Server: nginx
X-Powered-By: PleskLin}
I think the chunked header cause the problem but I have been googling for 2 days and there is no good solution or I cant find a good one.
Here is the screen shot of the error:
As you see in line 130, because _response.ContentLength is already -1 therefore iSize will be -1 and it throws exception at line 149.