You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WiX MSI安装器中HTTPS API调用失败但控制台应用正常的问题排查求助

WiX MSI安装器中HTTPS API调用失败但控制台应用正常的问题排查求助

我正在使用WiX Toolset为.NET Framework 4.8应用开发自定义安装程序,在安装过程中需要发起HTTPS API调用。这个API调用在独立控制台应用中能完美运行,但在MSI安装器中却持续失败。

问题详情

  • 控制台应用中,HTTP和HTTPS请求都能正常工作
  • MSI安装器中,HTTP请求成功,但HTTPS请求始终失败,错误信息如下:

Error :
An error occurred while server Configration : WebException occurred during API call:
https://{Domain}:443/api/RPA/RpaSetupLog
Status: ReceiveFailure
Response:
Message: The underlying connection was closed: An unexpected error occurred on a receive.
Stack trace: at System.Net. HttpWebRequest.GetResponse()
at CustomActions. CustomActions. SendDataToApi(String protocol, String domainOrlp, String port, String jsonData, String rootCertificateString, String intermediateCertificateString, String endDomainCertificateString) in
Occurred at line: 0

我已经在代码中添加了以下配置:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

控制台应用中这段代码能正常生效,但MSI安装器中依然无法解决问题。

已完成的检查

证书验证

  • 确认服务器使用的是有效证书;对于自签名证书,已经手动将根证书、中间证书和域名证书安装到生产系统的证书存储中

多环境测试结果

  • 本地机器:控制台应用和MSI安装器的HTTPS请求均正常工作
  • 生产系统:
    • 控制台应用的HTTP和HTTPS请求都正常
    • MSI安装器的HTTPS请求失败,HTTP请求正常

网络连通性检查

  • 验证生产系统可以解析并Ping通API域名
  • MSI安装器的HTTP请求成功,说明网络访问权限是正常的

代码实现

private static bool SendDataToApi(string protocol, string domainOrIp, string port, string jsonData)
{
    string apiUrl = $"{protocol}://{domainOrIp}:{port}/api/RPA/RpaSetupLogs";

    try
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiUrl);
        request.Method = "POST";
        request.ContentType = "application/json";
        request.Timeout = 30000;

        // Enable TLS 1.2
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

        // Bypass SSL Validation (Tried this as a workaround)
        ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;

        using (var writer = new StreamWriter(request.GetRequestStream()))
        {
            writer.Write(jsonData);
            writer.Flush();
        }

        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
        {
            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new InvalidOperationException($"API call failed with status: {response.StatusCode}");
            }
        }

        return true;
    }
    catch (WebException webEx)
    {
        Console.WriteLine($"WebException: {webEx.Message}, Status: {webEx.Status}");
        throw;
    }
}

环境详情

本地系统

  • Windows 10
  • .NET Framework 4.8
  • 控制台应用和MSI安装器的HTTPS请求均正常

生产系统

  • Windows Server 2019
  • 控制台应用HTTPS请求正常,但MSI安装器HTTPS请求失败
  • 控制台应用和MSI安装器的HTTP请求均正常

求助问题

  1. 为什么HTTPS请求在MSI安装器中失败,但在控制台应用中正常?
  2. 这是否与安装器的执行上下文、权限或环境设置有关?如果是,该如何调试或解决?
  3. WiX安装器是否需要特定配置才能支持安装过程中的HTTPS调用?

任何见解或建议都将非常感谢。

备注:内容来源于stack exchange,提问作者Meet Gajjar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.15 10:50:27