远程服务器返回错误:(407) 需要代理身份验证
当我调用 Web 服务时,出现此错误:
“远程服务器返回错误:(407) 需要代理身份验证”。
使代码正常工作
myProxy.Credentials = NetworkCredential("user", "password", "domain");
我了解了总体思路,并且可以通过在代码中添加或使用 DefaultCredentials 来 。我的问题是,如果没有这个,对 Web 服务的调用就可以在生产中正常工作。
似乎有一个涉及 Machine.config 的非代码解决方案,但它是什么?目前我无法访问生产盒的 machine.config 文件来查看它的样子。我尝试按如下方式更新 machine.config,但仍然收到 407 错误。
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true">
<bypasslist>
<clear />
</bypasslist>
<proxy proxyaddress="myproxy:9000"
usesystemdefault="false"
bypassonlocal="true"
autoDetect="False" />
</defaultProxy>
</system.net>
I'm getting this error when I call a web service:
"The remote server returned an error: (407) Proxy Authentication Required".
I get the general idea and I can get the code to work by adding
myProxy.Credentials = NetworkCredential("user", "password", "domain");
or by using DefaultCredentials in code. My problem is that the call to the web service works in production without this.
It seems like there is a non code solution involving Machine.config, but what is it? At the moment I can't get to the production box's machine.config file to see what that looks like. I tried updating my machine.config as follows, but I still get the 407 error.
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true">
<bypasslist>
<clear />
</bypasslist>
<proxy proxyaddress="myproxy:9000"
usesystemdefault="false"
bypassonlocal="true"
autoDetect="False" />
</defaultProxy>
</system.net>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
只需将其添加到配置中即可
Just add this to config
在以下代码中,我们不需要对凭据进行硬编码。
In following code, we don't need to hard code the credentials.
请咨询您的防火墙专家。
他们为 PROD 服务器打开防火墙,因此无需使用代理。
感谢您的提示帮助我解决了我的问题:
必须在两个位置设置凭据才能克服 407 错误:
瞧!
Check with your firewall expert.
They open the firewall for PROD servers so there is no need to use the Proxy.
Thanks your tip helped me solve my problem:
Had to to set the Credentials in two locations to get past the 407 error:
and voila!
可能是prod中的机器或者web.config有配置中的设置;您可能不需要代理标签。
Probably the machine or web.config in prod has the settings in the configuration; you probably won't need the proxy tag.
它是成功的。
It is successful.
写这个答案的想法是因为上面没有任何效果&您不想指定代理位置。
如果您使用的是
httpClient
那么请考虑这一点。如果您使用的是
HttpWebRequest
:请参考:https://medium.com/@siriphonnot/the-remote-server-returned-an-error-407-proxy-authentication-required-86ae489e401b
Thought of writing this answer as nothing worked from above & you don't want to specify proxy location.
If you're using
httpClient
then consider this.And if you're using
HttpWebRequest
:Kind referencce: https://medium.com/@siriphonnot/the-remote-server-returned-an-error-407-proxy-authentication-required-86ae489e401b
我有类似的代理相关问题。就我而言,添加以下内容就足够了:
I had a similar proxy related problem. In my case it was enough to add: