tags:

views:

202

answers:

3

The link below is an image URL where the extension has been stripped. I assume this is being done with content negotiation tools. I know that it's a GIF having viewed the HTML meta data with Firebug. What I would like to know is a simple way working in C# on .NET, how would I get the file type of this URL?

http://ep.yimg.com/ca/I/yhst-20493720720238%5F2066%5F63220718

With most image URLs it's easy. One can use string functions to find the file type in the URL.

Ex. /imageEx.png

+1  A: 

See Content-Type. You might also want to read up on content type spoofing.

Sinan Ünür
+2  A: 

You would have to read in the image and look for 'magic numbers' which can tell you what the file type really is. Here is an incomplete example of what I am talking about:

http://www.garykessler.net/library/file%5Fsigs.html

EDIT: OK, you don't have to do it this way in this context. I am not a web guy, so this is how I would have approached it :-)

Ed Swangren
+4  A: 

You're going to have to make an HTTP HEAD request, and then check the Content-Type on the response. I can't recall whether System.Net.HttpWebRequest supports HEAD requests, but that would be the place to start.

Alternatively, you could perform a full GET request, but that could have performance implications if all you need to know is Content-Type.

LorenVS