Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Getting the mime / content type of an http document

Getting the mime / content type of an http document

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminquestion
3 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jagadeesh VN
    wrote on last edited by
    #1

    Hi, Is there any way I can get the actual content type of a URL without downloading the file completely ? 1. I tried CHttpFile::QueryInfo with HTTP_QUERY_CONTENT_TYPE, But for that to work, I must call SendRequest, which will download the complete file. 2. I tried FindMimeFromData(...) with Url option, But its not even connecting to the internet to get the Mime type, instead I believe it checks only in the url. Sometimes the url may not be having any information about this and the server might set the mime type, so I need a method which will download only the Http response header and extract this information. Thanks Jugs "A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."

    S 1 Reply Last reply
    0
    • J Jagadeesh VN

      Hi, Is there any way I can get the actual content type of a URL without downloading the file completely ? 1. I tried CHttpFile::QueryInfo with HTTP_QUERY_CONTENT_TYPE, But for that to work, I must call SendRequest, which will download the complete file. 2. I tried FindMimeFromData(...) with Url option, But its not even connecting to the internet to get the Mime type, instead I believe it checks only in the url. Sometimes the url may not be having any information about this and the server might set the mime type, so I need a method which will download only the Http response header and extract this information. Thanks Jugs "A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."

      S Offline
      S Offline
      Stephen Hewitt
      wrote on last edited by
      #2

      You could ask the server - The response of a HTTP request gives the MIME type. To see what I'm talking about try this: 1. Open a command prompt and enter "telnet www.thecodeproject.com 80". 2. Now type the following, exactly (you will not be able to see what you're typing - The blank line at the end is important):

      HEAD /images/standard/logotop.gif HTTP/1.1 Host: www.thecodeproject.com

      The response from the server will indicate the content type (see the "Content-Type" header field). I'm not saying you have to do all this manually at the socket level (although to do so would not be hard), but if you can figure out how to send a HTTP "HEAD" request to the server and read the response using whatever framework or API you're into you should be able to do it. Steve

      J 1 Reply Last reply
      0
      • S Stephen Hewitt

        You could ask the server - The response of a HTTP request gives the MIME type. To see what I'm talking about try this: 1. Open a command prompt and enter "telnet www.thecodeproject.com 80". 2. Now type the following, exactly (you will not be able to see what you're typing - The blank line at the end is important):

        HEAD /images/standard/logotop.gif HTTP/1.1 Host: www.thecodeproject.com

        The response from the server will indicate the content type (see the "Content-Type" header field). I'm not saying you have to do all this manually at the socket level (although to do so would not be hard), but if you can figure out how to send a HTTP "HEAD" request to the server and read the response using whatever framework or API you're into you should be able to do it. Steve

        J Offline
        J Offline
        Jagadeesh VN
        wrote on last edited by
        #3

        Hi Steve, That was indeed very helpful. I used plain sockets and got this to work. Thanks a TON!!! Jugs "A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups