HTTP GET在浏览器中工作,但不与HTTPWebRequest

本文关键字:HTTPWebRequest 工作 GET 浏览器 HTTP | 更新日期: 2023-09-27 18:10:48

标题说明了这一点。我试图使用HTTP Web请求以编程方式更改网页的密码。当我通过Google Chrome(将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();

HTTP GET在浏览器中工作,但不与HTTPWebRequest

按照建议使用fiddler,结果发现它是用户代理头文件。谢谢你更正错别字L.B.:)