Reputation: 61
WebRequest request = WebRequest.Create(new Uri("http://istr03.izlesene.com/data/videos/7213/7213704-360_2-103k.mp4/e5ae7a74a30f645c6fc0c5aa0fde9076/531B29B7"));
request.Method = "HEAD";
using (WebResponse response = request.GetResponse()) {
double boyut = response.ContentLength / 1024 / 1024;
string tip = response.ContentType;
}
This code is working for other sites but for this url, an exception is raised; (500) internal server error.
What could be different that the code fails for this url?
Upvotes: 0
Views: 570
Reputation: 4360
I did use fiddler to see what is going on. the url you provided redirected to another URL .
HEAD http://istr03.izlesene.com/data/videos/7213/7213704-360_2-103k.mp4/e5ae7a74a30f645c6fc0c5aa0fde9076/531B29B7 HTTP/1.1
User-Agent: Fiddler
Host: istr03.izlesene.com
HTTP/1.1 302 Moved Temporarily
Via: 1.1 81.212.99.207 (McAfee Web Gateway 7.3.2.3.0.16052)
Date: Fri, 07 Mar 2014 14:45:20 GMT
Server: nginx/1.4.4
Location: http://sstr06.izlesene.com/data/videos/7213/7213704-360_2-103k.mp4?token=WCk3CCIxJYVC0ESMOs1cFw&ts=1394210720
Connection: Keep-Alive
Content-Type: text/html
Content-Length: 160
So you need to parse Location from first response and do another request to server with HEAD method and you will get content length of video.
HEAD http://sstr06.izlesene.com/data/videos/7213/7213704-360_2-103k.mp4?token=WCk3CCIxJYVC0ESMOs1cFw&ts=1394210720 HTTP/1.1
User-Agent: Fiddler
Host: sstr06.izlesene.com
HTTP/1.1 200 OK
Via: 1.1 81.212.99.207 (McAfee Web Gateway 7.3.2.3.0.16052)
Date: Fri, 07 Mar 2014 14:45:21 GMT
ETag: "53037f98-cc2f46"
Server: nginx/1.4.4
Connection: Keep-Alive
Content-Type: video/mp4
Accept-Ranges: bytes
Last-Modified: Tue, 18 Feb 2014 15:43:20 GMT
Content-Length: 13381446
Upvotes: 1
Reputation: 42493
You need to set an User-Agent http header. This specific server expects that probably to sniff the capabilities of the client.
Adapt your code to get the HttpWebRequest and set the UserAgent property:
var request = (HttpWebRequest) WebRequest.Create(
new Uri("http://your url here"));
request.Method = "HEAD";
request.UserAgent = "spider/1.0";
using (WebResponse response = request.GetResponse())
{
double boyut = response.ContentLength / 1024 / 1024;
string tip = response.ContentType;
}
The content-length of your url is: 13381446
and the content-type is: video/mp4
Upvotes: 1