Question
· Apr 24, 2019

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
Log in or sign up to continue

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;

  1. Extend the EnsLib.HL7.Operation.HTTPOperation
  2. Copy the SendMessage method from the super EnsLib.HL7.HTTPOperation
  3. 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
}
}