Question
· 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())

}

}

Discussion (10)0
Log in or sign up to continue

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.

 #1)

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

#2)

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.