Http Header code (example 200,404,..)
-
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! -
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!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.
-
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.
Thanks! But it just determine "OK" not the code!! I need the code number exactly!! How could I get code number?!!!!
-
Thanks! But it just determine "OK" not the code!! I need the code number exactly!! How could I get code number?!!!!
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 ofStatusCode
.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.”
-
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 ofStatusCode
.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.”
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.
-
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.
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.”
-
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.”
Thanks alot of both of you!! :) I would try to read documentation carefully before asking something like this. :wtf: