none
Invoke-WebRequest with non supported encoding name RRS feed

  • Question

  • I'm requesting some web content that returns a content-type of: text/xml; charset="UTF-8"

    This causes an error: Invoke-WebRequest : '"UTF-8"' is not a supported encoding name.

    Is there a way to get around this?


    Paulo Morgado


    Monday, May 6, 2013 11:54 AM

Answers

  • Seems like the only way is to go directly to .NET:

    $xml = New-Object xml
    
    $resolver = New-Object -TypeName System.Xml.XmlUrlResolver
    $resolver.Credentials = [System.Net.CredentialCache]::DefaultCredentials
    
    $reader = New-Object -TypeName System.Xml.XmlReaderSettings
    $reader.XmlResolver = $resolver
    
    $reader = [System.Xml.XmlReader]::Create($url, $reader)
    
    $xml.Load($reader)
    


    Paulo Morgado

    Tuesday, May 7, 2013 12:11 PM

All replies