Setting the ServerCertificateValidationCallback delegate ServerCertificateValidationCallback not help you - SSL / TLS is not protocol - protocol violation is related to HTTP headers (for example, a long time after TLS has been set).
There is a .NET useUnsafeHeaderParsing .NET configuration flag that controls whether such violations are ignored or not.
Using reflection, it can also be set from the runtime. This Technet forum answer gives a great example of how to do this in PowerShell, we can wrap this in a great function, as shown below:
function Set-UseUnsafeHeaderParsing { param( [Parameter(Mandatory,ParameterSetName='Enable')] [switch]$Enable, [Parameter(Mandatory,ParameterSetName='Disable')] [switch]$Disable ) $ShouldEnable = $PSCmdlet.ParameterSetName -eq 'Enable' $netAssembly = [Reflection.Assembly]::GetAssembly([System.Net.Configuration.SettingsSection]) if($netAssembly) { $bindingFlags = [Reflection.BindingFlags] 'Static,GetProperty,NonPublic' $settingsType = $netAssembly.GetType('System.Net.Configuration.SettingsSectionInternal') $instance = $settingsType.InvokeMember('Section', $bindingFlags, $null, $null, @()) if($instance) { $bindingFlags = 'NonPublic','Instance' $useUnsafeHeaderParsingField = $settingsType.GetField('useUnsafeHeaderParsing', $bindingFlags) if($useUnsafeHeaderParsingField) { $useUnsafeHeaderParsingField.SetValue($instance, $ShouldEnable) } } } }
And then use like:
Set-UseUnsafeHeaderParsing -Enable
before calling Invoke-WebRequest
source share