獲取圖片鏈接:http://file.api.weixin.qq.com/cgi-bin/media/get?access_token={0}&media_id={1}
如今會提示錯誤{"errcode":43003,"errmsg":"require https hints: [vkjeLhqge-92sgla!] Please View: [https://w.url.cn/s/ApJ0Ci4] "},如下圖:
解決辦法:把http改為https
把獲取圖片鏈接改為:https://file.api.weixin.qq.com/cgi-bin/media/get?access_token={0}&media_id={1}
測試過后下載成功
把http改為https后,C#代碼用WebClient請求https頁面會出錯:基礎連接已經關閉: 未能為 SSL/TLS 安全通道建立信任關系。
解決辦法:
創建WebClient前加上下面這句,使用回調的方法進行證書驗證。
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
///
/// 回調驗證證書問題
///
/// 流對象
/// 證書
/// X509Chain
/// SslPolicyErrors
///
private bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
return true;
}