Invoke-Webrequest Encoding - TechNet - Microsoft

文章推薦指數: 80 %
投票人數:10人

When i use Invoke-WebRequest or Invoke-RestMethod the ÆØÅ are not formatted ... charset=utf-8" } UseBasicParsing = $true ErrorAction ... TechNet Products ITResources Downloads Training Support Products Windows WindowsServer SystemCenter MicrosoftEdge   Office Office365 ExchangeServer   SQLServer SharePointProducts SkypeforBusiness Seeallproducts» Resources Channel9Video EvaluationCenter LearningResources MicrosoftTechCompanionApp MicrosoftTechnicalCommunities MicrosoftVirtualAcademy ScriptCenter ServerandToolsBlogs TechNetBlogs   TechNetFlashNewsletter TechNetGallery TechNetLibrary TechNetMagazine TechNetWiki WindowsSysinternals VirtualLabs Solutions Networking CloudandDatacenter Security Virtualization Updates ServicePacks SecurityBulletins WindowsUpdate Trials WindowsServer2016 SystemCenter2016 Windows10Enterprise SQLServer2016 Seealltrials» RelatedSites MicrosoftDownloadCenter MicrosoftEvaluationCenter Drivers WindowsSysinternals TechNetGallery Training Expert-led,virtualclasses TrainingCatalog ClassLocator MicrosoftVirtualAcademy FreeWindowsServer2012courses FreeWindows8courses SQLServertraining MicrosoftOfficialCoursesOn-Demand Certifications Certificationoverview Specialoffers MCSECloudPlatformandInfrastructure MCSE:Mobility MCSE:DataManagementandAnalytics MCSEProductivity Otherresources MicrosoftEvents ExamReplay BornToLearnblog Findtechnicalcommunitiesinyourarea Azuretraining OfficialPracticeTests Supportoptions Forbusiness Fordevelopers ForITprofessionals Fortechnicalsupport Supportofferings Moresupport MicrosoftPremierOnline TechNetForums MSDNForums SecurityBulletins&Advisories NotanITpro? MicrosoftCustomerSupport MicrosoftCommunityForums ThisforumhasmigratedtoMicrosoftQ&A.VisitMicrosoftQ&Atopostnewquestions. LearnMore ResourcesforITProfessionals Signin UnitedStates(English) Brasil(Português)Česko(Čeština)Deutschland(Deutsch)España(Español)France(Français)Indonesia(Bahasa)Italia(Italiano)România(Română)Türkiye(Türkçe)Россия(Русский)ישראל(עברית)المملكةالعربيةالسعودية(العربية)ไทย(ไทย)대한민국(한국어)中国(中文)台灣(中文)日本(日本語)  HomeLibraryWikiLearnGalleryDownloadsSupportForumsBlogs Askaquestion Quickaccess Forumshome Browseforumsusers FAQ Searchrelatedthreads RemoveFromMyForums Answeredby: Invoke-WebrequestEncoding ArchivedForums901-920  >  WindowsPowerShell Question 1 Signintovote Hiall, IhavebeenplayingaroundwiththeAPIonmyPhillipsHUE. Myproblemiswithencodingoftheresponse.IliveinDenmarkwhereweusespecielcharectersÆØÅ. WheniuseInvoke-WebRequestorInvoke-RestMethodtheÆØÅarenotformattedcorrectly.Whenitapinto.Netdirectlyitworksasexspected: $splatParameters=@{ Uri="$($site)sensors/8" Method="GET" Headers=@{ "Accept-Charset"="utf-8" "Accept"="application/json" "Content-Type"="application/json;charset=utf-8" } UseBasicParsing=$true ErrorAction='SilentlyContinue' }; $test=Invoke-WebRequest@splatParameters Theresponse: {"state":{"flag":false,"lastupdated":"none"},"config":{"on":true,"reachable":true},"name":"Wakeupsovev??relse","type":"CLIPGenericFlag","modelid":"WAKEUP","manufacturername":"Philips","swversion":"1.0","uniqueid":"L_04_GSoTj","recycle":true} Whenitrythe.Net: $req=[System.Net.WebRequest]::Create("$($site)sensors/8") $req.ContentType="application/json;charset=utf-8" $req.Accept="application/json" $resp=$req.GetResponse() $reader=new-objectSystem.IO.StreamReader($resp.GetResponseStream()) $test1=$reader.ReadToEnd() Theresponse: {"state":{"flag":false,"lastupdated":"none"},"config":{"on":true,"reachable":true},"name":"Wakeupsoveværelse","type":"CLIPGenericFlag","modelid":"WAKEUP","manufacturername":"Philips","swversion":"1.0","uniqueid":"L_04_GSoTj","recycle":true} Amidoingsomethingwrong? Sunday,March18,20185:44PM Answers 0 Signintovote Hi, Basedonmyresearch,pleasetrytheworkaroundmethodinthefollowinglinkandseeifitworks: Invoke-RestMethodandInvoke-WebRequestEncodingbug https://windowsserver.uservoice.com/forums/301869-powershell/suggestions/13685217-invoke-restmethod-and-invoke-webrequest-encoding-b BestRegards, Albert Pleaseremembertomarktherepliesasananswersiftheyhelp. IfyouhavefeedbackforTechNetSubscriberSupport,contact [email protected] Itseemstobeworkingwhentranslatingthestring.Thereareothersthataretalkingaboutthis: https://github.com/PowerShell/PowerShell/issues/3267?_pjax=%23js-repo-pjax-container Itseemsthatit'snotme.MaybetheAPIisnotreturningtheContent-Typeproperly.Butfornowitworksflawlesslywiththe.Net System.Net.WebRequest.IlbeusingthiswiththisAPI. Thanksfortheanswers:) Proposedasanswerby AlbertLingMicrosoftcontingentstaff Wednesday,March28,20187:19AM Markedasanswerby ThomasH_DK Tuesday,April3,201810:44AM Monday,March19,20182:28PM Allreplies 0 Signintovote Try: $test=Invoke-WebRequest @splatParameters-ContentType  'application/json;charset=utf-8' \_(ツ)_/ Sunday,March18,20187:55PM 0 Signintovote Try: $test=Invoke-WebRequest @splatParameters-ContentType  'application/json;charset=utf-8' \_(ツ)_/ Ialreadytriedspecifyingthecontenttypelikethat.Sadlythesameresult:( Sunday,March18,20188:03PM 0 Signintovote Hi, Basedonmyresearch,pleasetrytheworkaroundmethodinthefollowinglinkandseeifitworks: Invoke-RestMethodandInvoke-WebRequestEncodingbug https://windowsserver.uservoice.com/forums/301869-powershell/suggestions/13685217-invoke-restmethod-and-invoke-webrequest-encoding-b BestRegards, AlbertPleaseremembertomarktherepliesasananswersiftheyhelp. IfyouhavefeedbackforTechNetSubscriberSupport,contact [email protected] Proposedasanswerby AlbertLingMicrosoftcontingentstaff Wednesday,March28,20187:19AM Monday,March19,20186:06AM 0 Signintovote Hi, Basedonmyresearch,pleasetrytheworkaroundmethodinthefollowinglinkandseeifitworks: Invoke-RestMethodandInvoke-WebRequestEncodingbug https://windowsserver.uservoice.com/forums/301869-powershell/suggestions/13685217-invoke-restmethod-and-invoke-webrequest-encoding-b BestRegards, Albert Pleaseremembertomarktherepliesasananswersiftheyhelp. IfyouhavefeedbackforTechNetSubscriberSupport,contact [email protected] Itseemstobeworkingwhentranslatingthestring.Thereareothersthataretalkingaboutthis: https://github.com/PowerShell/PowerShell/issues/3267?_pjax=%23js-repo-pjax-container Itseemsthatit'snotme.MaybetheAPIisnotreturningtheContent-Typeproperly.Butfornowitworksflawlesslywiththe.Net System.Net.WebRequest.IlbeusingthiswiththisAPI. Thanksfortheanswers:) Proposedasanswerby AlbertLingMicrosoftcontingentstaff Wednesday,March28,20187:19AM Markedasanswerby ThomasH_DK Tuesday,April3,201810:44AM Monday,March19,20182:28PM 0 Signintovote Hi, Thanksforyourfeedback.Ifthereisanythingelsewecandoforyou,pleasefeelfreetopostintheforum. BestRegards, AlbertPleaseremembertomarktherepliesasananswersiftheyhelp. IfyouhavefeedbackforTechNetSubscriberSupport,contact [email protected] Tuesday,March20,20188:46AM  ©2022Microsoft.Allrightsreserved.Newsletter|ContactUs|PrivacyStatement|TermsofUse|Trademarks



請為這篇文章評分?