cho*_*obo 3 c# post encoding httpwebrequest character-encoding
我正在尝试与第三方系统集成,并且在文档中提到当他们通过HttpPost发送xml数据时,他们有时会使用" text/xml charset = \"UTF-8**""作为"Content-Type" ",在其他情况下,他们使用"**application/x-www.form-urlencoded "作为内容类型.
解析请求会有什么不同吗?现在我只使用以下代码拉取帖子数据:
StreamReader reader = new StreamReader(Request.InputStream);
String xmlData = reader.ReadToEnd();
Run Code Online (Sandbox Code Playgroud)
当您打开流阅读器时,您应该传递HttpRequest对象上指定的编码.
StreamReader reader = new StreamReader(request.InputStream, request.ContentEncoding);
string xmlData = reader.ReadToEnd();
Run Code Online (Sandbox Code Playgroud)
这应该允许您将请求的原始内容放入正确的.NET字符串中,无论使用何种编码.
| 归档时间: |
|
| 查看次数: |
2715 次 |
| 最近记录: |