【发布时间】:2021-10-19 17:12:01
【问题描述】:
我有一个用 C# 编写的 UWP 应用。
对于某些特定用户(即特定 PC),该应用无法执行 HTTP 请求。
那些电脑没有使用任何 VPN,他们关闭了任何防火墙或防病毒软件,他们尝试了多个连接(例如家庭路由器、电话热点、公共 wifi 等),但结果总是相同。
打开浏览器并浏览到
他们能够看到正确的页面(实际上是纯文本“OK”)。
但如果他们使用应用程序(使用 C# 执行 HTTP GET 调用),则此应用程序会失败。
这是我们使用的 C# 代码:
string pingUrl = "https://ltbackend.azurewebsites.net/diagnostic/ping";
HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Get, pingUrl);
using (HttpClient httpClient = new HttpClient())
{
try
{
using (HttpResponseMessage response = await httpClient.SendAsync(req))
{
string stringRes = await response.Content.ReadAsStringAsync();
HttpStatusCode respCode = response.StatusCode;
// .... our biz logic with stringRes and respCode...
}
}
catch (HttpRequestException e)
{
// the ping request for those users throws this exception...
// the error message is "An error occurred while sending the request."
}
}
【问题讨论】:
-
可能有很多东西 - 寻找某些 tls 版本、标头、用户代理等。作为响应,您究竟会得到什么?你的uwp有权限使用网络吗?
-
通常,这可以工作(对于遍布全球的数十万个安装),但对于那些特定的设备,我们实际上没有得到响应,我们得到一个带有消息“发送时发生错误”的 HttpRequestException请求。”
-
不要创建/处理大量的 HttpClient。跨请求重用它们。系统时钟是否同步?错误的时钟可能会导致误报 ssl 故障。他们的浏览器是否使用代理?
标签: c# networking uwp httprequest