HTTP GET在浏览器中工作,但不适用于HTTPWebRequest

时间:2014-06-29 21:03:08

标签: c# http get httpwebrequest

标题解释了它。我正在尝试使用HTTP Web请求以编程方式更改网页的密码。当我通过谷歌浏览器(在地址栏中粘贴uri)时,密码更改有效。这是我在Chrome中检查时得到的标题。

Remote Address:10.160.70.55:443
Request URL:https://10.160.70.55/cgi-bin/check_user.cgi?Type=basic&Current=78-62-118-112-106-108-56&Password=98-96-102-96-106-96
Request Method:GET

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8,fr;q=0.6,ar;q=0.4
Authorization:Digest username="admin", realm="Secure Access", nonce="f3c6fcd9a549a42e9aac22818cb0f5ad", uri="/cgi-bin/check_user.cgi?Type=basic&Current=78-62-118-112-106-108-56&Password=98-96-102-96-106-96", response="cd17523a279f044d086b5bd0245eda0e", qop=auth, nc=0000001b, cnonce="9bd719c27efd9721"
Connection:keep-alive
Host:10.160.70.55

当我尝试以编程方式执行此操作时,我收到了OK(200)代码,但密码更改不起作用。这是我的代码。

System.Uri uri2 = new Uri(string.Format("https://{0}/cgi-bin/check_user.cgi?Type=basic&Current=78-62-118-112-106-108-56&Password=98-96-102-96-106-96", ip));
                        HttpWebRequest request2 = (HttpWebRequest)WebRequest.Create(uri) as HttpWebRequest;
                        request2.Accept = "text/html";
                        request2.Credentials = new NetworkCredential("admin", "M@ster1");
                        request2.Method = WebRequestMethods.Http.Get;
                        HttpWebResponse response2 = (HttpWebResponse)request.GetResponse();
                        WriteLog(response2.StatusDescription.ToString());

                        response2.Close();

1 个答案:

答案 0 :(得分:0)

建议使用fiddler,结果是用户代理头。谢谢你纠正错字L.B. :)