CipherIS
asked on
C# - Could not create SSL/TLS secure channel - Authentication Issues
I am writing code and implementing the code sample in the below url from Silicon Expert.
https://www.siliconexpert.com/apidocs/content/list-part-search
The sample code produced error: "The request was aborted: Could not create SSL/TLS secure channel."
Searching I found that the below code should be implemented.
<?xml version="1.0" encoding="UTF-8"?><Service Result><St atus><Code >1</Code>< Message>In valid User Name Or Password</Message><Success >false</Su ccess></St atus></Ser viceResult >
Yet, when I log into the site and perform a search there is no issue.
Anyone see anything that I'm missing? Want to check to see if it is the code or the site.
https://www.siliconexpert.com/apidocs/content/list-part-search
The sample code produced error: "The request was aborted: Could not create SSL/TLS secure channel."
Searching I found that the below code should be implemented.
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(AllwaysGoodCertificate);
Below is the full example. String username = "MyUserName";
String password = "MyPassword";
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(AllwaysGoodCertificate);
string url = "https://app.siliconexpert.com/SearchService/search/authenticateUser?login=" + username + "&apiKey=" + password;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Credentials = CredentialCache.DefaultCredentials;
CookieContainer cookieContainer = request.CookieContainer = new CookieContainer();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
String searchUrl = "https://app.siliconexpert.com/SearchService/search/xref?parts=[{\"partNumber\":\"bav99\"}]&crossType=B";
request = (HttpWebRequest)WebRequest.Create(searchUrl);
request.CookieContainer = cookieContainer;
response = (HttpWebResponse)request.GetResponse();
String results = new System.IO.StreamReader(response.GetResponseStream(), ASCIIEncoding.ASCII).ReadToEnd();
Console.WriteLine(results);
Console.ReadLine();
I am receiving <?xml version="1.0" encoding="UTF-8"?><Service
Yet, when I log into the site and perform a search there is no issue.
Anyone see anything that I'm missing? Want to check to see if it is the code or the site.
ASKER
Framework I'm using is 4.5.
I found the issue. Apparently, another login is needed for the API. Waiting for those credentials and then how it goes.
I found the issue. Apparently, another login is needed for the API. Waiting for those credentials and then how it goes.
I would also remove SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls as they are both already hacked. If you end up transmitting with either of those protocols the information is public.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Which version of .Net Framework your app is using?
Regards,
Chinmay.