Reputation: 2205
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!
Upvotes: 4
Views: 4416
Reputation: 1863
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.
Upvotes: 1