Encoding with HttpClient in .NET 4.5

前端 未结 2 1995
小鲜肉
小鲜肉 2020-12-19 02:47

I\'m consuming some data using the fogbugz XML API. This API always offers data as UTF-8.

When using the WebClient class for making a request I am able

2条回答
  •  被撕碎了的回忆
    2020-12-19 03:09

    You should be able to use GetStringAsync - I'd expect the encoding to be determined by the headers in the HTTP response. If the server doesn't specify the encoding, then you should potentially ask for that to be fixed.

    Alternatively, if you're fetching XML data, just fetch it as a byte array and parse that binary directly - the XML declaration should specify the encoding for non-UTF-8/UTF-16 data anyway, so I'd argue that actually there's less room for error this way.

提交回复
热议问题