0

当我的网站的站点地图更新时,我正在尝试 ping Google,但我需要知道 Google 或任何其他服务返回哪个状态代码。我的代码如下:

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();
4

2 回答 2

1

试试 HttpWebResponse.StatusCode

于 2010-04-10T07:33:55.817 回答
1

您需要使用响应 - 将其分配给HttpWebResponse变量:

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

枚举会告诉你返回了HttpStatusCode什么状态码。

于 2010-04-10T07:40:04.660 回答