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

添加SSL证书后仅浏览器调用API出现404及无响应问题

问题:MVC应用调用HTTPS端口的WebAPI无响应,控制台调用正常

背景

企业内部环境中,我们在IIS的85端口部署了WebAPI,从86端口的MVC HelperApp调用该API完全正常。为提升安全性,我们给该API在IIS的444端口绑定了SSL证书。

问题现象

  • Postman、SoapUI、C#控制台应用测试444端口的HTTPS API均正常
  • MVC HelperApp调用时偶尔返回404,深入调试后发现:
    • 将调用代码封装到C# DLL后,控制台应用调用DLL的PostAPI方法可正常运行
    • MVC HelperApp调用DLL时,执行到await client.PostAsync(url, data);就卡住,既不返回结果也不抛出异常,Get请求也出现同样情况
    • 若将目标URL替换为https://httpbin.org/post或85端口的HTTP地址,MVC应用调用完全正常

怀疑排查方向

目前推测是端口或证书相关的浏览器端调用限制,正在排查以下不熟悉的点:

  • 主题备用名称(Subject Alternative Name):现有示例均为WWW地址,我们未使用此类地址
  • 证书创建时的友好名称(Friendly Name)
  • 跨域资源共享(CORS Cross-Origin Resource Sharing)

调用代码

控制台应用与MVC应用中的调用代码完全一致:

var lib = new HttpsLibrary.ApiCaller();
lib.makeHttpsCall();

DLL核心代码

public async Task<string> makeHttpsCall()
{
    try
    {
        List<Quote> quotes = new List<Quote>();

        quotes.Add(CreateDummyQuote());

        var json = JsonConvert.SerializeObject(quotes);
        var data = new StringContent(json, Encoding.UTF8, "application/json");


        var url = "https://httpbin.org/post";  // 这个地址在浏览器端调用正常
        //url = "https://thepath:444//api/ProcessQuotes"; // 444端口仅在浏览器端调用失败,控制台调用正常
        //url = "http://thepath:85/api/ProcessQuotes";  // 85端口调用正常
        

        var client = new HttpClient();

        var response = await client.PostAsync(url, data); // <<< 从浏览器调用时,这行永远不返回
        //var response = await client.GetAsync(url);  // Get请求也是同样结果
        
        var result = await response.Content.ReadAsStringAsync();

        return result;

    }
    catch (Exception ex)
    {
        throw;
    }

}

内容的提问来源于stack exchange,提问作者Ray

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 07:20:28