Krishnamuthu Ve... · Feb 4, 2019

How to set Content-Type header in http outbound adapter. It always sends the content-type as plain text/html.

How to set Content-Type header in http outbound adapter. It always sends the content-type as plain text/html. I am uploading a image / Pdf.

Class TEST.BusinessOperation.SaveFile Extends Ens.BusinessOperation

Parameter ADAPTER = "EnsLib.HTTP.OutboundAdapter";

Property Adapter As EnsLib.HTTP.OutboundAdapter;

Parameter INVOCATION = "Queue";

Method SaveFile(pRequest As Messages.File, Output pResponse As Messages.SaveFileResponse) As %Status
     set fileName = pRequest.fileName
    set Content = pRequest.fileContent
    set tSC = ..Adapter.PutURL(URL,.HttpResponse,"",Content.Read())



4 0 10 667



Here is the code I use:

Set tHttpRequest = ## class (% Net.HttpRequest). New ()
From tHttpRequest.ContentTypeSet ("application / json")
From tHttpRequest.SetHeader ("Authorization", "Basic [Base64String]")
From tHttpRequest.ContentCharsetSet ("utf-8")
From tHttpRequest.EntityBody.Write (tJsonTxt)

The above  example would work but how can I do it with Ensemble Outbound adapter. Since we have no reference of HttpRequest object.

(I did not find a field like ContentType in Adapter class.)

Have you tried this instead of ContentTypeSet?

SetHeader ("Content-Type", "application/json")

This seems to work for us.

Ola Gilberto,

Tudo bem? Por acaso ja usou Server-Sent Events com Emsemble/Cache?



Thanks to all for your valuable responses. 

Hi, Krishna muthu.

This is the only ESB adapter that I do not use, because debugging esb ends up taking many steps to create a
% Net.HttpRequest. With this we adopt the strategy of making the requisitions manually.

Sorry for the mistakes this message has been translated by google translate.

No, we have no object reference of HttpRequest (SetHeader is a method of HttpRequest object)

Everardo, bom dia.

Desculpa mas pra te falar a vdd nem sei o que é Server-Sent Events 

Consegue mandar um exemplo do que isso faria

Redefine HTTP adapter like this:

Class Production.Adapter.HTTPOutboundAdapter Extends EnsLib.HTTP.OutboundAdapter

Method PostURL(pURL As %String, Output pHttpResponse As %Net.HttpResponse, pFormVarNames As %String, pData...) As %Status [ CodeMode = expression ]
..SendFormDataArray(.pHttpResponse, "POST", ..GetRequest(), .pFormVarNames, .pData, pURL)

ClassMethod GetRequest() As %Net.HttpRequest
    set request = ##class(%Net.HttpRequest).%New()
    set request.ContentType  =  "application/pdf"
    quit request


And use it instead of default adapter.

For better performance it would be better to reuse the request.

Alternatively, you can call SendFormDataArray adapter method directly and it accepts request object.


You need to get %Net.HttpRequest in hands to set your property Content Type.


instead of PutURL(...) you have to use method SendFormDataURL(....)  of EnsLib.HTTP.OutboundAdapter

more details in docs here:

Creating Custom HTTP Requests

If you use the more common methods of the HTTP outbound adapter (such as Get), the adapter automatically creates and sends an HTTP request, which can include either form data or a request body. In special cases, you may want to create a custom HTTP request so that you can specify details such as proxy authorization or a different character encoding.