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#
  4. Http Header code (example 200,404,..)

Http Header code (example 200,404,..)

Scheduled Pinned Locked Moved C#
csharptutorialquestion
7 Posts 3 Posters 0 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.
  • N Offline
    N Offline
    Nafiseh Salmani
    wrote on last edited by
    #1

    I want to determine HTTP header code of a URL by C# code. How could I get that? I use the following code : public Dictionary<string, string> GetHTTPResponseHeaders(string Url) { Dictionary<string, string> HeaderList = new Dictionary<string, string>(); WebRequest WebRequestObject = HttpWebRequest.Create(Url); WebResponse ResponseObject = WebRequestObject.GetResponse(); foreach (string HeaderKey in ResponseObject.Headers) { HeaderList.Add(HeaderKey, ResponseObject.Headers[HeaderKey]); textBox1.Text += HeaderKey + ": " + ResponseObject.Headers[HeaderKey]+" " ; } ResponseObject.Close(); return HeaderList; } but It does not contain of HTTP header Code!

    C 1 Reply Last reply
    0
    • N Nafiseh Salmani

      I want to determine HTTP header code of a URL by C# code. How could I get that? I use the following code : public Dictionary<string, string> GetHTTPResponseHeaders(string Url) { Dictionary<string, string> HeaderList = new Dictionary<string, string>(); WebRequest WebRequestObject = HttpWebRequest.Create(Url); WebResponse ResponseObject = WebRequestObject.GetResponse(); foreach (string HeaderKey in ResponseObject.Headers) { HeaderList.Add(HeaderKey, ResponseObject.Headers[HeaderKey]); textBox1.Text += HeaderKey + ": " + ResponseObject.Headers[HeaderKey]+" " ; } ResponseObject.Close(); return HeaderList; } but It does not contain of HTTP header Code!

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Nafiseh Salmani wrote:

      WebResponse ResponseObject = WebRequestObject.GetResponse();

      This should be cast to an HttpWebResponse if the Url you are passing uses HTTP or HTPS as the protocol.

      HttpWebResponse responseObject = (HttpWebResponse)WebRequestObject.GetResponse();

      You will then find a StatusCode property which contains the detail you want.

      User group: Scottish Developers Blog: Can Open... Worms? Everywhere! Quote: Man who stand on hill with mouth open wait long time for roast duck to drop in.

      N 1 Reply Last reply
      0
      • C Colin Angus Mackay

        Nafiseh Salmani wrote:

        WebResponse ResponseObject = WebRequestObject.GetResponse();

        This should be cast to an HttpWebResponse if the Url you are passing uses HTTP or HTPS as the protocol.

        HttpWebResponse responseObject = (HttpWebResponse)WebRequestObject.GetResponse();

        You will then find a StatusCode property which contains the detail you want.

        User group: Scottish Developers Blog: Can Open... Worms? Everywhere! Quote: Man who stand on hill with mouth open wait long time for roast duck to drop in.

        N Offline
        N Offline
        Nafiseh Salmani
        wrote on last edited by
        #3

        Thanks! But it just determine "OK" not the code!! I need the code number exactly!! How could I get code number?!!!!

        H 1 Reply Last reply
        0
        • N Nafiseh Salmani

          Thanks! But it just determine "OK" not the code!! I need the code number exactly!! How could I get code number?!!!!

          H Offline
          H Offline
          Henry Minute
          wrote on last edited by
          #4

          Read the documentation!! here[^] StatusCode is an enumeration, 'OK' = 200. Just write yourself a method to return a string of the numbers based on the value of StatusCode.

          Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

          C 1 Reply Last reply
          0
          • H Henry Minute

            Read the documentation!! here[^] StatusCode is an enumeration, 'OK' = 200. Just write yourself a method to return a string of the numbers based on the value of StatusCode.

            Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

            C Offline
            C Offline
            Colin Angus Mackay
            wrote on last edited by
            #5

            Henry Minute wrote:

            Read the documentation!! here[^]

            Documentation has a use? I thought it was just a jolly for technical writers to get paid to do something no one reads! Wow! Didn't I learn something today. :rolleyes:

            User group: Scottish Developers Blog: Can Open... Worms? Everywhere! Quote: Man who stand on hill with mouth open wait long time for roast duck to drop in.

            H 1 Reply Last reply
            0
            • C Colin Angus Mackay

              Henry Minute wrote:

              Read the documentation!! here[^]

              Documentation has a use? I thought it was just a jolly for technical writers to get paid to do something no one reads! Wow! Didn't I learn something today. :rolleyes:

              User group: Scottish Developers Blog: Can Open... Worms? Everywhere! Quote: Man who stand on hill with mouth open wait long time for roast duck to drop in.

              H Offline
              H Offline
              Henry Minute
              wrote on last edited by
              #6

              Of course, I don't use it myself...... :-D

              Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

              N 1 Reply Last reply
              0
              • H Henry Minute

                Of course, I don't use it myself...... :-D

                Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

                N Offline
                N Offline
                Nafiseh Salmani
                wrote on last edited by
                #7

                Thanks alot of both of you!! :) I would try to read documentation carefully before asking something like this. :wtf:

                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