WPF C# WebClient 对特定端口和 https 上的请求给出例外
这个问题真的很困扰我,我已经研究了好几天了,没有解决办法。当使用 WebClient POST 请求到 https web-url 时,请求大约需要 30 秒,最终崩溃并出现 WebException,显示“底层连接已关闭,发送时发生意外错误”。当我使用服务器 IP 地址而不是名称时,它可以工作并且我没有遇到异常。当使用 WebRequest 或 HttpWebRequest 时,我得到了相同的行为。任何浏览器(即使将其作为 WebBrowserControl 嵌入到应用程序中)都可以与该 URL 配合使用。
我用它发送 POST 参数,但这实际上并不重要,它会抛出带有或不带有 post 数据的异常。我在 Windows 7 上运行 .NET4
WebClient webclient = new WebClient();
var parameters = new NameValueCollection
{
{"user", "me"},
};
byte[] bytes = webclient.UploadValues("https://server.com:12345/", "POST", parameters);
有帮助吗? Stackoverflow 上还有其他几篇文章,但都没有提出解决方案。是的,SSL 证书是有效的,并且不是自签名的或其他任何东西(再次强调:浏览器对 URL 没有任何问题)。
编辑:使用正确的英文消息更正了异常
编辑2:也许我应该添加该服务器是防火墙后面的 Ubuntu 服务器上的 Apache2
This one really bugs me, I've been researching this for days without a solution. When using a WebClient POST request to a https web-url, the request takes about 30 seconds and finally crashes with a WebException saying "the underlying connection was closed an unexpected error occurred on a send". When I'm using the servers IP address instead of the name, it works and I don't get an exception. I'm getting the same behavior when using WebRequest or HttpWebRequest instead. Any browser (even when using it embedded in the Application as a WebBrowserControl) works fine with the URL.
I'm sending POST parameters with it, but that in fact doesn't matter, it's throwing the exception with or without the post data. I'm running .NET4 on Windows 7
WebClient webclient = new WebClient();
var parameters = new NameValueCollection
{
{"user", "me"},
};
byte[] bytes = webclient.UploadValues("https://server.com:12345/", "POST", parameters);
Any help? There's a couple other posts on Stackoverflow, but none of them brought be to a solution. And yes, the SSL certificate is valid and not self signed or anything (again: browser does not have any problem with the URL).
EDIT: corrected exception with correct english message
EDIT2: maybe I should add that the server is an Apache2 on Ubuntu server behind a firewall
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此端点是否设置为进行身份验证(可能使用 Windows/NTLM)?
在这种情况下,您需要告诉 Web 客户端对象使用 默认网络凭据。
是否涉及代理?
如果是这样,请尝试设置 Web 客户端对象上的默认代理。
并请发布正确的异常错误消息。
Is this endpoint setup to authenticate, perhaps with Windows/NTLM?
In that case you will need to tell the Web Client object to use the default network credentials.
Is there a proxy involved?
If so, try to set the default proxy on the Web Client object.
And please post the correct Exception error message.