Discussion (9)1
Log in or sign up to continue

I do not understand your question, can you please explain what you need to achieve?

%Net.HttpRequest class is used to create an HTTP request that is sent to the counterpart/endpoint and a response message is then received from the counterpart. How can you possibly generate a response that, by definition, has to be received from a remote system?

Clearly I'm missing something.

Code adapted with your details:

Set objHttpRequest = ##class(%Net.HttpRequest).%New()
Set objHttpRequest.ContentType = "application/fhir+json"
Set objHttpRequest.Server = "localhost"
Set objHttpRequest.Port = "52773"
Set pRequest = {"asd":"asd"}
Do objHttpRequest.EntityBody.Write(pRequest.%ToJSON())
If objHttpRequest.Send("POST", "/aktest/test") {
    Set objHttpResponse = objHttpRequest.HttpResponse
    If $IsObject(objHttpResponse.Data) {
        Set objStream = objHttpResponse.Data
        Set json = ""
        While ('objStream.AtEnd) {
            Set json = json _ objStream.ReadLine()
        }
    } Else {
        Set json = objHttpResponse.Data
    }
    Set httpStatus = objHttpResponse.StatusCode
    Write "Status: ", httpStatus, !
    Write "Response: ", json, !
}