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.
{
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())
}
}
Hi
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?
Obrigado,
Everardo
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.
#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