以下代码在本地主机上运行正常,但在将我的API部署到Microsoft Azure后出现了上述错误。
我的代码如下:
public class UsersController : Controller
{
private readonly HttpClient _client;
public UsersController()
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
_client = new HttpClient { BaseAddress = new Uri("https://pincode.saratchandra.in/api") };
_client.DefaultRequestHeaders.Accept.Clear();
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
}
public JsonResult GetAddress(int pincode)
{
var response =_client.GetAsync("/pincode/125112").Result;
//Here it throws an exception: got no response
if (response.IsSuccessStatusCode)
{
}
return Json(ApiResult.Success(), JsonRequestBehavior.AllowGet);
}
以上调用未收到任何响应,只收到以下错误信息:
请求已中止:无法创建 SSL/TLS 安全通道