質問

ローカルマシン用のプロキシサーバーをバイパスし、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リクエストがIPの形で来ていることがわかります 172.24.1.87 私のIPはそうです 172.24.17.220.

これを避ける方法はありますか?これが403エラーの根本原因だと思います。

助けてください。ありがとう、

subhen

役に立ちましたか?

解決

そのIPアドレスはあなたのプロキシのアドレスです...そして、あなたはそのプロキシになるようにWeb要求のプロキシを設定しています。

なぜあなたはそれがプロキシを使用しないと期待するのですか?

リクエストをバイパスしていることに注意してください ローカルマシンではありません から それがあなたの混乱のポイントであれば、ローカルマシン。

編集:何が起こっているのか本当に知りたい場合は、 Wireshark これにより、マシンから来るすべてのパケットが表示されます。

「プロキシを使用しないで」を指定したい場合は、次のようなことをします。

request.Proxy = GlobalProxySelection.GetEmptyWebProxy();

他のヒント

httpwebrequestのプロキシプロパティのデフォルト値は常にwebrequest.getsystemwebproxy()の結果です。

プロキシを使用したくない場合は、デフォルトのプロキシをオーバーライドする必要があります

Request = (System.Net.HttpWebRequest)HttpWebRequest.Create(strRootURI); 
Request.Proxy = null;
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top