Below code works fine on localhost but Getting the above error after deployed my api on microsoft azure .
My code is as follows:
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);
}
Didn't get any response for above call just get the error
The request was aborted: Could not create SSL/TLS secure channel
The error “The request was aborted: Could not create SSL/TLS secure channel.” can happen during any download HTTP request. This error generally will correspond to firewalls, proxies or DNS filtering blocking the connection or an SSL/TLS cipher misconfiguration.
However, the "Could not create SSL/TLS secure channel" error usually means that there's something wrong with the server certificate, e.g. the certificate is for a different hostname, or otherwise invalid, or not trusted etc.
A common reason you may receive the error Could not establish trust relationship for the SSL/TLS secure channel is because the SSL certificate isn't trusted. If the SSL certificate is not trusted, you will need to install the SSL certificate's root certificate.
We have recently had a number of similar issues with API's.
In our case these were resolved by changing the Security Protocol Type to TLS 1.2, like so:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
This appears to be a result of the deprecation of SSL, and the recommendation of the adoption of TLS 1.2 by the PCI as of the middle of 2016. See here for more
EDIT:
This works for me:
class Program
{
private static HttpClient _client;
static void Main(string[] args)
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
_client = new HttpClient ();
_client.DefaultRequestHeaders.Accept.Clear();
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = _client.GetAsync("https://pincode.saratchandra.in/api/pincode/125112").Result;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With