简体   繁体   English

在 vb.net 中验证有效凭据后,WebRequest 无法验证无效的代理凭据

[英]WebRequest is not able to validate invalid proxy credentials after validating valid credentials in vb.net

I'm validating proxy credentials using WebRequest.DefaultWebProxy.我正在使用 WebRequest.DefaultWebProxy 验证代理凭据。 After giving valid credentials when I'm using invalid credentials it also works fine.在我使用无效凭据时提供有效凭据后,它也可以正常工作。 so it is not validating proxy credentials here.所以这里没有验证代理凭据。

here is my code.这是我的代码。

Dim webProxy = New Net.WebProxy(Uri)
webProxy.Credentials = New Net.NetworkCredential("userName", "Password")
WebRequest.DefaultWebProxy = webProxy 

I reproduced this issue successfully and it seems like setting the Proxy at global level using WebRequest.DefaultWebProxy is caching the credentials for some time even after setting it to Nothing .我成功地重现了这个问题,似乎使用WebRequest.DefaultWebProxy在全局级别设置 Proxy 会缓存凭据一段时间,即使将其设置为Nothing

I couldn't find a solution to this problem but I can suggest you a workaround.我找不到这个问题的解决方案,但我可以建议你一个解决方法。 What you can do is to create a separate utility(executable file) and pass your credentials while invoking this utility.您可以做的是创建一个单独的实用程序(可执行文件)并在调用此实用程序时传递您的凭据。 By this approach you will not face any issue with the caching and you will receive the correct response.通过这种方法,您将不会遇到任何缓存问题,并且您将收到正确的响应。

Please try if it works for you.请尝试它是否适合您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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