0

I'm trying to ping Google when my web site's sitemap is updated but I need to know which status code does Google or any other service returns. My code is below:

HttpWebRequest rqst = (HttpWebRequest)WebRequest.Create("http://search.yahooapis.com/ping?sitemap=http%3a%2f%2fhasangursoy.com.tr%2fsitemap.xml");
rqst.Method = "POST";
rqst.ContentType = "text/xml";
rqst.ContentLength = 0;
rqst.Timeout = 3000;

rqst.GetResponse();

2 Answers 2

1

You need to use the response - assign it to a HttpWebResponse variable:

HttpWebResponse resp = (HttpWebResponse)rqst.GetResponse();
HttpStatusCode respStatusCode = resp.StatusCode;

The HttpStatusCode enumeration will tell you what status code was returned.

Sign up to request clarification or add additional context in comments.

4 Comments

Code is ok but I get "OK" as status code. I needed code like 200, 404 etc.
I'ts done. If I use int respStatusCode = resp.StatusCode; this returns the status code. For more details: msdn.microsoft.com/en-us/library/system.net.httpstatuscode.aspx
@Hasan Gürsoy - it is an enumeration, so yes, it will be implicitly cast to an integer.
@Hasan Gürsoy - glad to have been of help :)
1

Try HttpWebResponse.StatusCode out

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.