【发布时间】:2021-08-06 07:50:38
【问题描述】:
错误 CS0176:无法使用实例引用访问静态成员 `System.Net.WebRequest.Create(string)',而是使用类型名称对其进行限定
为什么这段代码不起作用
using System;
using System.Net;
using System.Net.Http;
namespace main
{
class firstreq
{
public static void Main(string[] args)
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("https://192.168.240.1");
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
HttpWebRequest webRequest2 = (HttpWebRequest)webRequest2.Create("https://192.168.240.1/getname");
HttpWebResponse response2 = (HttpWebResponse)webRequest2.GetResponse();
}
}
}
}
我试过去除静电,但它不起作用,任何解决方案都会很酷,谢谢
【问题讨论】:
-
在
HttpWebRequest webRequest2 = (HttpWebRequest)webRequest2.Create("https://192.168.240.1/getname");中,第二个webRequest2应该是WebRequest。