The request was aborted: Could not create SSL/TLS secure channel
I am trying to get the data from my shopify store but i am getting error on that below line
using (var resp = (HttpWebResponse)req.GetResponse())
below is the whole code which i am using
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace ShopifyIntegrationProjectDemo
{
class Program
{
static void Main(string[] args)
{
Program p = new Program();
p.GetCustomers();
// GetCustomers();
}
public string GetCustomers()
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
const string Url = "https://fd49a55f3afafdff141b8ab40809516b:
[email protected]/admin/orders.json";
var req = (HttpWebRequest)WebRequest.Create(Url);
req.Method = "GET";
req.ContentType = "application/json";
req.Credentials = GetCredential(Url);
req.PreAuthenticate = true;
req.KeepAlive = false;
// req.ProtocolVersion = HttpVersion.Version10;
using (var resp = (HttpWebResponse)req.GetResponse())
{
if (resp.StatusCode != HttpStatusCode.OK)
{
string message = String.Format("Call failed. Received HTTP {0}", resp.StatusCode);
throw new ApplicationException(message);
}
var sr = new StreamReader(resp.GetResponseStream());
return sr.ReadToEnd();
}
}
private static CredentialCache GetCredential(string url)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
var credentialCache = new CredentialCache();
credentialCache.Add(new Uri(url), "Basic", new NetworkCredential("KEY", "Password"));
return credentialCache;
}
}
}