Reputation: 1492
The below requests always takes the default Content Type irrespective of what I am setting. I set to application/xml, but still it goes as application/json. This problem however is not there when I invoke the service via 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 -> No Content-Type Set
Upvotes: 0
Views: 567
Reputation: 3205
How did you check that default Content-Type?
Maybe you missed something about how HTTP really works?
When you send some data with POST
or PUT
request, you can set Content-Type for this data. If you want to retrieve some data from the server in the format which you want, you can set header Accept
, but when you set this header, it does not mean, that you really get this data in the asked format, it only depends on the realization of this particular server. To some examples.
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>
Upvotes: 0