distinguish html link and image link like Facebook attach in .NET
like facebook attach link,
when i share a link -> facebook fetch the html page
when i share a image link -> facebook fetch the image
so at server side (.NET, C#), how can i distin开发者_运维百科guish a html link or image link
any help?
You could try a couple things:
- Do a regex on the URL and check for a file extension. E.g.
\.(png|jpg|gif|bmp)$
- Actually retrieve the document, and check the mime type
Also, check answers to this question:
Regex to check if valid URL that ends in .jpg, .png, or .gif
The most recent answer there mentions a library called FastImage.
精彩评论