当前位置: 首页 > news >正文

服务器接口调用微信小程序获取手机号接口报:The SSL connection could not be established, see inner exception.

使用了linux服务器,发布.net8的webapi,其中登录接口调用了微信小程序获取手机号的接口,本地测试环境一直没有问题,当发布到服务器之后一直报:The SSL connection could not be established, see inner exception.
一直怀疑证书配置问题,或者是我的nginx配置证书不正确的问题,也怀疑是docker镜像内部无法访问微信小程序接口的问题;
最后发现和服务器没有关系,是我自己的程序里面在调用微信小程序接口的时候,使用了HttpWebRequest,这个比较老了,很多都不支持这种了,所以一直报错,最后换成httpclient调用post接口就可以了;
老旧的调用方法如下:
public static string Post(string url, string data) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; using (StreamWriter streamWriter = new StreamWriter(request.GetRequestStream())) { streamWriter.Write(data); } HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (StreamReader readStream = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { return readStream.ReadToEnd(); } }
新的成功的调用方法如下:

private static string PostResponse(string url, string con)
{
//if (url.StartsWith("https"))
// System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
if (url.StartsWith("https"))
{
// 启用所有支持的 TLS 版本
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls13 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
}
string resString = null;
using (HttpClient httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
var content = new StringContent(con);
HttpResponseMessage response = httpClient.PostAsync(url, content).Result;

if (response.IsSuccessStatusCode)
{
resString = response.Content.ReadAsStringAsync().Result;
}
}
return resString;
}

http://www.rkmt.cn/news/53056.html

相关文章:

  • 2025留学美国被开除怎么办?申诉挽回/学业急救/身份保留/转学规划/签证补救机构哪家强
  • WPS用Qt还情有可原
  • 2025年评价高的UV 软膜广告灯箱厂家最新TOP排行
  • 2025年山西口碑好的纪念馆展示柜定制厂家排行Top10推荐
  • C# 14 新功能全面解析:提升生产力与性能的革命性更新
  • 2025年优秀的软件行业体系认证三体系认证品牌实力推荐榜
  • 2025年11月中国枸杞企业口碑推荐榜单
  • 学业危机速看!2025美国紧急转学机构哪家好,学分对接/院校适配全解析
  • 探索Word2Vec:从文本向量化到中文语料处理 - 指南
  • 基于DeepSeek-R1 15b微调训练自主的领域大模型,附带工程代码
  • CF2161D题解
  • linux address
  • Flutter 登录状态管理与 Token 持久化方案
  • 经济越差,越是好产品脱颖而出的时候
  • 实用指南:DevOps 生命周期完全指南
  • 算法第三章实践作业
  • 2025年比较好的茶叶烘干网带行业内口碑厂家排行榜
  • 2025年热门的保健托玛琳床垫厂家选购指南与推荐
  • 2025年评价高的除四害权威推荐
  • 2025年美国付费实习中介哪家靠谱,名企内推/背景提升/求职规划/全程护航机构推荐
  • 基于单片机的液体流量检测设计 (仿真+电路+代码)(51+1602+YFS201+BZ+KEY2) 0464
  • 2025 CSP-S2 游记 -
  • 2025年知名的防静电劳保鞋厂家最新推荐排行榜
  • 2025年知名的别墅装修最新推荐榜
  • linux 64 编译 32
  • 2025年比较好的白水苹果高品质供应榜
  • 2025年正规的企业短视频账号代运营TOP品牌榜
  • 2025年口碑好的内衣贴牌厂家推荐及选择建议
  • 2025年比较好的定制豪华骑马抽最新TOP排名厂家
  • 2025年热门的全屋定制门墙柜厂家最新推荐榜