简体   繁体   中英

Test Proxy to see if it requires Authentication

I have a list of proxies that I want to loop through and test to make sure they are working and also test to make sure that they do not require a username and password.

However, the test does not seem to be working correctly. For example I have one proxy that I know requires a username and password to use, but it is somehow getting through the test.

Here is the sample code that I have:

HttpWebRequest webReq = (HttpWebRequest)System.Net.HttpWebRequest.Create("http://www.google.com");
webReq.Proxy = new WebProxy(proxy);
HttpWebResponse webRes = (HttpWebResponse)webReq.GetResponse();
if (webRes.StatusCode != HttpStatusCode.ProxyAuthenticationRequired)
{

    Stream myStream = webRes.GetResponseStream();
    if (myStream != null)
    {
        success = true;
    }
}

For example the following proxy requires authentication: "66.60.148.11:3128". However when I run the code, the webRes.StatusCode comes back as OK and passes the webRes.StatusCode != HttpStatusCode.ProxyAuthenticationRequired test.

Any ideas or sugestions are appreciated.

Thanks!

I would imagine the request to the proxy that is allowing it through (so to speak) is not following HTTP standards by not returning a 407 status code. You can view this by doing a packet sniff with something like WireShark http://www.wireshark.org/ or using browser debug tools like Chromes Developer Tools (Ctrl+Shift+I). You could also check to see what status code is being returned by looking at the value of webRes.StatusCode for this case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM