Powershell wget protocol violation -
i trying browse command on embedded webserver using wget / invoke-webrequest. how can error avoided?
wget : server committed protocol violation. section=responseheader detail=cr must followed lf
already tried multiple things, example below without success:
[system.net.servicepointmanager]::servercertificatevalidationcallback = {$true}
when using bits instead, error i'm getting
start-bitstransfer : server did not return file size. url might point dynamic content. content-length header not available in server's http reply.
thanks clem
setting servercertificatevalidationcallback
delegate won't - ssl/tls not protocol being referred - protocol violation regards http headers (eg. long after tls has been established).
there's .net configuration flag called useunsafeheaderparsing
controls whether such violations ignored or not.
using reflection, can set runtime. this technet forum answer give's great example of how in powershell, can wrap in nifty function 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 use like:
set-useunsafeheaderparsing -enable
before calling invoke-webrequest
Comments
Post a Comment