我有以下代码绕过本地计算机的代理服务器,然后发送WebRequest。

                System.Net.HttpWebRequest Request;
                System.Net.WebResponse Response;
                System.Net.CredentialCache MyCredentialCache;

编辑1

//System.Net.WebProxy proxyObject = new WebProxy("http://172.24.1.87:8080",true);

            string strRootURI = "http://172.24.18.240/webdav/";
            string strUserName = "UsName";
            string strPassword = "Pwd";
           // string strDomain = "Domain";
            string strQuery = "";
            byte[] bytes = null;
            System.IO.Stream RequestStream = null;
            System.IO.Stream ResponseStream = null;
            System.Xml.XmlTextReader XmlReader = null;

            try
            {
                // Build the SQL query.
                strQuery = "myWebDavVerb";

                // Create a new CredentialCache object and fill it with the network
                // credentials required to access the server.
                MyCredentialCache = new System.Net.CredentialCache();
                MyCredentialCache.Add(new System.Uri(strRootURI), "Basic", new System.Net.NetworkCredential(strUserName, strPassword));//, strDomain)


                // Create the HttpWebRequest object.
                Request = (System.Net.HttpWebRequest)HttpWebRequest.Create(strRootURI);


                // Add the network credentials to the request.
                Request.Credentials = MyCredentialCache;

                      // Request.Proxy = proxyObject;
                    // Specify the method.
                    Request.Method = "PROPFIND";
    }

现在,当我尝试执行时,我遇到了403个错误。因此,我检查了服务器日志,发现HTTP/1.0请求即将到来。 172.24.1.87 虽然我的IP是 172.24.17.220.

有没有办法避免这种情况?我认为这是403错误的根本原因。

请帮忙。谢谢,

Subhen

有帮助吗?

解决方案

该IP地址是您的代理人的地址...您正在为Web请求设置代理,以使其成为代理。

您为什么期望它不使用代理?

请注意,您正在绕过请求 本地机器,不是 本地机器,如果那是您的困惑。

编辑:如果您真的想知道发生了什么,请抓住 Wireshark 这将使您看到来自机器的所有数据包。

如果要指定“不要使用代理”,请执行类似的操作:

request.Proxy = GlobalProxySelection.GetEmptyWebProxy();

其他提示

httpwebrequest具有其代理属性的默认值,这始终是WebRequest.getSystemwebproxy()的结果,它是您在IE中配置的代理

如果您不想使用代理,则需要覆盖默认代理

Request = (System.Net.HttpWebRequest)HttpWebRequest.Create(strRootURI); 
Request.Proxy = null;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top