以下请求始终采用默认的内容类型,无论我设置的是什么。我设置为application / xml,但它仍然作为application / json。但是当我通过Postman调用服务时,这个问题就不存在了。
Set objHTTPRequest=##class(%Net.HttpRequest).%New()
Set objHTTPResponse=##class(%Net.HttpResponse).%New()
Do objHTTPRequest.SetHeader("Authorization", "username:password")
Do objHTTPRequest.SetHeader("Content-Type", "application/xml")
Do objHTTPRequest.Send("GET","url")
Set Op=objHTTPRequest.HttpResponse.Data.Read()
zw objHTTPRequest - >没有内容类型集
答案 0 :(得分:0)
您是如何检查默认内容类型的?
也许你错过了一些关于HTTP如何运作的东西?
当您使用POST
或PUT
请求发送一些数据时,您可以为此数据设置Content-Type。如果要以所需的格式从服务器检索某些数据,可以设置标题Accept
,但是当您设置此标题时,并不意味着您确实以所要求的格式获取此数据,它只取决于这个特定服务器的实现。举个例子。
set ht=##class(%Net.HttpRequest).%New()
set ht.Server="example.org"
set ht.Port=80
set ht.Username="username"
set ht.Password="password"
#; we a going to send some xml
do ht.ContentBody.Write("<root></root>")
#; for this data we can set ContentType
set ht.ContentType="application/xml"
#; then we POST this data, where 1 it is just test flag, for debug
set sc=ht.Post("/somepath", 1)
#; As a result you can see that Content-Type has our value
POST /somepath HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; Cache;)
Host: example.org
Accept-Encoding: gzip
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
Content-Length: 13
Content-Type: application/xml
<root></root>