Invoke-restmethod encoding problem

Welcome Forums General PowerShell Q&A Invoke-restmethod encoding problem

Viewing 4 reply threads
  • Author
    Posts
    • #250913
      Participant
      Topics: 1
      Replies: 2
      Points: 19
      Rank: Member

      Hi Guys,

      When i’m running the following Powershell code I get the wrong encoding. I need it to be in utf-8 but it’s not

      I get these weird characters:

      “De sørgende enker”

      “NÃ¥r Luksusfælden til efterÃ¥ret vender tilbage”

      In Denmark we use letters ÆØÅ 🙂

      Do you guys know what i’m doing wrong?

       

      • This topic was modified 1 month, 1 week ago by dvidebaek39.
      • This topic was modified 1 month, 1 week ago by dvidebaek39.
    • #251123
      Participant
      Topics: 0
      Replies: 81
      Points: 362
      Helping Hand
      Rank: Contributor

      You could test by adding charset=utf-8 to your -ContentType value.

    • #251375
      Participant
      Topics: 1
      Replies: 2
      Points: 19
      Rank: Member

      You could test by adding charset=utf-8 to your -ContentType value.

      It didn’t work I tried the following:

      One funny thing. When I ran the following code I didn’t get the weird characters:
      So I think there is something wrong in my script somewhere. Here is my “epg grabber script”:
      I now believe it’s not the invoke-restmethod that generates the weird characters. Maybe it’s $EPG.Save('C:\users\dvide\OneDrive\Desktop\testxml.xml')
      I’m lost hope somebody can help me
      • This reply was modified 1 month ago by grokkit.
      • This reply was modified 1 month ago by grokkit.
      • This reply was modified 1 month ago by grokkit.
      • This reply was modified 1 month ago by grokkit.
    • #251690
      Participant
      Topics: 15
      Replies: 1776
      Points: 3,218
      Helping Hand
      Rank: Community Hero

      Invoke-RestMethod is just returning at payload from an API. This can be tested by using curl or postman and looking at the XML that is returned. You can save the content directly with Out-File, but it appears you should be concentrating on where exactly the characters appears starting at the source. Another option:

      https://stackoverflow.com/questions/30265973/how-can-i-force-or-specify-encoding-type-using-xml-save

    • #251981
      Participant
      Topics: 1
      Replies: 2
      Points: 19
      Rank: Member

      Invoke-RestMethod is just returning at payload from an API. This can be tested by using curl or postman and looking at the XML that is returned. You can save the content directly with Out-File, but it appears you should be concentrating on where exactly the characters appears starting at the source. Another option:

      https://stackoverflow.com/questions/30265973/how-can-i-force-or-specify-encoding-type-using-xml-save

      Used -outfile and loaded the xml. That way it worked. The link advised I couldn’t get to work. I’m Running this on PowerShell 7.0.3 by the way.

       

      Don’t know whats going on in PowerShell… Maybe it’s a bug?
Viewing 4 reply threads
  • You must be logged in to reply to this topic.