【问题标题】:HTTP POST Content-TypeHTTP POST 内容类型
【发布时间】:2017-01-24 15:08:59
【问题描述】:
我有这个 HTTP POST 服务:
POST /test/test.asmx/getValues HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: length
xmlstr=string
我想要这项服务:
POST /test/test.asmx/getValues HTTP/1.1
Host: localhost
Content-Type: application/xml
Content-Length: length
xmlstr=string
如何将服务器的 Content-Type 值更改为 application/xml?
我正在使用 IIS 和 VB .NET。
谢谢。
【问题讨论】:
标签:
vb.net
iis
http-headers
http-post
content-type
【解决方案1】:
Content-Type 请求标头描述了请求正文中数据的格式。
xmlstr=string 使用application/x-www-form-urlencoded 格式编码。
如果您说的是Content-Type: application/xml,那么我希望正文格式为 XML(例如 <xmlstr>string</xmlstr>)。
您发送到服务器的 Content-Type 对服务器响应的数据类型没有标准化影响。
The Accept header 可以请求特定的内容类型:
POST /test/test.asmx/getValues HTTP/1.1
Host: localhost
Accept: application/xml
Content-Type: application/x-www-form-urlencoded
Content-Length: length
xmlstr=string
……但服务端代码必须注意并尊重它。
服务器还可能允许使用非标准请求标头、存储在 URL 的查询字符串中的数据或正文中的数据来请求特定格式。
它总是取决于服务器端代码支持什么。