我正在尝试与第三方系统集成,文档中提到当他们通过 HttpPost 发送 xml 数据时,他们有时会使用“text/xml charset=\"UTF-8**"”对于“Content-Type”,在其他情况下,他们使用“**application/x-www.form-urlencoded”作为 Content-Type。
解析请求会有什么不同吗?现在我只是使用以下代码提取帖子数据:
StreamReader reader = new StreamReader(Request.InputStream);
String xmlData = reader.ReadToEnd();
最佳答案
当您打开流阅读器时,您应该传递在 HttpRequest 对象上指定的编码。
StreamReader reader = new StreamReader(request.InputStream, request.ContentEncoding);
string xmlData = reader.ReadToEnd();
这应该允许您将请求的原始内容转换为适当的 .NET 字符串,而不管使用何种编码。
关于c# - 接收具有不同编码的发布数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5835752/