سؤال

لدي الرمز التالي الذي يتجاوز خادم الوكيل للجهاز المحلي ثم إرسال 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.

الرجاء المساعدة. شكرًا،

سوبهن

هل كانت مفيدة؟

المحلول

عنوان IP هذا هو عنوان الوكيل الخاص بك ... وأنت تقوم بتعيين الوكيل لطلب الويب ليكون هذا الوكيل.

لماذا تتوقع ألا تستخدم الوكيل؟

لاحظ أنك تتجاوز الطلبات إلى الجهاز المحلي ، لا من الجهاز المحلي ، إذا كان هذا هو نقطة الارتباك.

تحرير: إذا كنت تريد حقًا معرفة ما يحدث ، فاحصل على Wireshark مما سيتيح لك رؤية جميع الحزم القادمة من جهازك.

إذا كنت ترغب في تحديد "لا تستخدم وكيلًا" ، فقم بعمل شيء مثل:

request.Proxy = GlobalProxySelection.GetEmptyWebProxy();

نصائح أخرى

HTTPWebRequest لديه قيمة افتراضية لخاصية الوكيل الخاصة بها ، وهذا دائمًا ما يكون نتيجة لـ webrequest.getSystemWebroxy () وهو الوكيل الذي قمت بتكوينه في أي

إذا كنت لا ترغب في استخدام وكيل تحتاج إلى تجاوز الوكيل الافتراضي

Request = (System.Net.HttpWebRequest)HttpWebRequest.Create(strRootURI); 
Request.Proxy = null;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top