问题
Michael Lei · 四月 21

来自英文社区的问题:流中的HTTPMessage空值

我对EnsLib.HTTP.GenericOperation类进行了操作。此操作发送以下json消息:

<HTTPMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:s="http://www.w3.org/2001/XMLSchema">

<Stream>

{ "resourceType":"Bundle", "id":"ec5ffdbe-3739-47e6-81e4-2b0498e99fb8", "meta":[ { "lastUpdated":"2020-09-20T15:04:17.764+02:00" }], "type":"searchset", "total":"1", "link":[ { "relation":"self", "url":"https:\/\/xxx:5665\/api\/fhir\/DSTU3\/CarePlan?encounter=861241" }], "entry":[ { "fullUrl":"https:\/\/xxx:5665\/api\/fhir\/DSTU3\/CarePlan\/23104", "resource":[ { "resourceType":"CarePlan", "id":"23104", "identifier":[ { "system":"urn:hcis:mrns", "value":"23104" }] }], "addresses":[ { "reference":"Condition\/76741" }], "subject":[ { "reference":"Patient\/10055765" }] }] }

</Stream><Type>

CG

</Type>

</HTTPMessage>

我将其发送到具有EnsLib.REST.GenericService类的服务的同一名称空间(localhost:9980)。收到消息流为空,为什么?

<HTTPMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:s="http://www.w3.org/2001/XMLSchema">

<Stream></Stream>

<Type>BG</Type>

<HTTPHeaders><HTTPHeadersItem HTTPHeadersKey="CONTENT-LENGTH">0</HTTPHeadersItem><HTTPHeadersItem HTTPHeadersKey="CONTENT-TYPE">text/plain; charset="UTF-8"

</HTTPHeadersItem><HTTPHeadersItem HTTPHeadersKey="StatusLine">HTTP/1.1 500 Internal Server Error</HTTPHeadersItem></HTTPHeaders>

</HTTPMessage>

 
 
00
2 0 1 17
Log in or sign up to continue

不知你用的什么版本的产品,如果是2019.3.0之前的版本,需要手动在HTTP header中设定content-length

可以参考下面代码

ClassMethod GetGenericMessage(request As %String) As %Status
{
               set status = $$$OK, kb = "ENSEMBLE"
                set url = "rdr/interpreter/query?kbcode="_kb
                /// Get the message from Antrim
                set stream = request.StreamGet()
                set xStream = stream.Read(3500000)
                $$$TRACE("*****Stream String: "_xStream)
                set contentLength = $length(xStream)
                $$$TRACE("*****Length "_contentLength)
                /// Set the headers for posting orders/results to CDS.
                set tRequest=##class(EnsLib.HTTP.GenericMessage).%New()
                set headerA=##class(%ArrayOfDataTypes).%New()
                do headerA.SetAt("POST","httprequest")
                do headerA.SetAt(url,"url")
                do headerA.SetAt("gzip","accept-encoding")
                do headerA.SetAt("Mozilla/4.0 (compatible; Cache;)","user-agent")
                do headerA.SetAt(contentLength,"content-length")
                do headerA.SetAt("application/json","content-type")
                set tRequest.HTTPHeaders = headerA
                $$$TRACE("*****tRequest: "_tRequest)
                set tRequest.Stream = stream
               quit tRequest
}

如果是2019.3或者之后的版本,HTTP header会自动设定content-length的值。