HL7 HTTP - Change Content-Type
Hi,
I would like to use EnsLib.HL7.Operation.HTTPOperation for sending HL7 messages via HTTP. It sends the Content-Type as "text/html"
I would like to change it to something else, say "text/plain". I cannot see a way to do it.
I have now written a custom Operation (based on EnsLib.HTTP.OutboundAdapter) and modifying the Content-Type while POSTing using SendFormDataArray(). It's bit frustrating to parse the response etc.,
I would rather prefer to use HTTPOperation of HL7. Can somebody help?
Thanks.
Discussion (1)1
Comments
You can change the header keys of a %Net.HttpRequest
// Make Request
SET tHttpRequest=##class(%Net.HttpRequest).%New()
// Set header
SET tSC = tHttpRequest.SetHeader("Content-Type", "text/plain")
// Check for Errors
THROW:$$$ISERR(tSC) ##class(%Exception.StatusException).CreateFromStatus(tSC)Thus, to put this all together;
- Extend the EnsLib.HL7.Operation.HTTPOperation
- Copy the SendMessage method from the super EnsLib.HL7.HTTPOperation
- Make a small change to set the header after the first line.
// Sample Code, Not Complete
Class Niko.EnsLib.HL7.Operation.HTTPOperation Extends EnsLib.HL7.Operation.HTTPOperation
{
Method SendMessage(pMsgOut As EnsLib.HL7.Message, Output pMsgIn As EnsLib.HL7.Message, pExpectedSequenceNumber As %String) As %Status
{
Set pMsgIn=$$$NULLOREF, tHttpRequest=##class(%Net.HttpRequest).%New(), tHttpRequest.WriteRawMode=1
// Add these two lines after the firt in SendMessage. Change the content type to your desired header.
SET tSC = tHttpRequest.SetHeader("Content-Type", "text/plain")
THROW:$$$ISERR(tSC) ##class(%Exception.StatusException).CreateFromStatus(tSC)
// Copy the rest of the SendMessage Method from the standard EnsLib.HL7.Operation.HTTPOperation
}
}