Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, July 14, 2020 4:20 AM
public string getWebResponse(string address)
{
System.Net.WebResponse webResponse = null;
System.Net.SecurityProtocolType SecurityProtocol = new System.Net.SecurityProtocolType();
System.Net.WebRequest webRequest = System.Net.WebRequest.Create(address);
//if (address.StartsWith("https", StringComparison.InvariantCultureIgnoreCase))
// GetUriCookieContainer(webRequest.RequestUri);
//else
//webRequest.Credentials = System.Net.CredentialCache.DefaultCredentials; // if needed by server
try
{
webResponse = webRequest.GetResponse();
}
catch (Exception ex) { MessageBox.Show(this, ex.Message, "getWebResponse - webRequest.GetResponse() error"); }
how do I set the System.Net.SecurityProtocol for the webrequest?
All replies (5)
Tuesday, July 14, 2020 3:02 PM
This error indicates an issue setting up the SSL stream. It could be a protocol handshaking issue. It depends on your framework. Newer frameworks use the OS default which would include TLS 1.2 but older versions won't. Most endpoints have switched to TLS 1.2 so if you're using a version of the framework prior to 4.7 (I think) then you'll have to force your code to the newer protocol.
The correct approach is documented here. Ideally just set ServicePointManager to use the OS default if you're targeting older framework versions.
Michael Taylor http://www.michaeltaylorp3.net
Tuesday, July 14, 2020 6:13 PM
thx of reply. I'm using .net 4.7.2 I've tried using different protocol. the only one that worked for the particular site is Tls12
however at the end the end result html is only full of scripts and some irrelevant text. the part I'm interested in is nt present. I tried entering the address in internet explorer, chrome, edge, they all display showed what Im' interested..
what should I do?
Tuesday, July 14, 2020 6:20 PM
I'm confused as to your problem. You talked about getting an SSL issue which means you wouldn't get any results. If you are getting results then SSL wouldn't be an issue at all.
Having said that, if you're trying to screen scrape then you cannot use the HTML anyway. Most sites dynamically load data after the HTML is loaded. You cannot get that data from the HTML via HttpWebRequest. You have to emulate the site behavior and run the same queries it runs behind the scenes to get the data that is being dynamically loaded. That is beyond what this post was about though.
Michael Taylor http://www.michaeltaylorp3.net
Wednesday, July 15, 2020 4:32 PM
Hi, I would suggest you enable newer TLS version in your application, but you have to update your project to use .NET framework version or to use this solution to enable TLS 1.2 if you're stuck with older .NET framwork up to 4.0 inclusively. You could also use Fiddler application to track down concrete requests and responses.
Wednesday, July 22, 2020 2:41 AM
Hi gg edm,
First, your .NetFramework version is 4.7.2 and it uses Tls1.2 by default.
>>I've tried using different protocol. the only one that worked for the particular site is Tls12
When you use .NET Framework 4.7 and higher, ServicePointManager will use the default security protocol configured in the operating system.
To get the default operating system selection, you need not to set a value for the ServicePointManager.SecurityProtocol property, which defaults to SecurityProtocolType.SystemDefault.
Which version of Windows is you? It is also possible that your system does not enable TLS 1.2 by default.
And you can be set in: Control Panel -> Network and Internet -> Internet Options -> Advanced.
Then have your error resolved? If not, please refer to the following suggestions.
1.Run Visual Studio as an administrator.
2.Have you installed the certificate of the certification authority on your computer? And make sure your certificate is valid.
3.If the user has access to the certificate? If not, please refer to this thread.
There are more discussions and suggestions in these threads you can refer to.
[The request was aborted: Could not create SSL/TLS secure channel]
[The request was aborted: Could not create SSL/TLS secure channel]
Hope these are helpful to you.
Best Regards,
Daniel Zhang
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].