Question
· Sep 3, 2018

HTTP POST - unsupported media type - JSON

In a EnsLib.REST.Operation I have...

Set tSC=..Adapter.Post(.tHttpResponse,,pRequest.stream)

This sends JSON string over HTTP

I am getting this error back from the server

ErrHTTPStatus: Received non-OK status 415 from remote HTTP server: 'HTTP/1.1 415 Unsupported Media Type'

I have been told that the media type should be "JSON"

how do I go about changing the media-type of the HTTP Request?

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

Redefine HTTP adapter like this:

Class Production.Adapter.HTTPOutboundAdapter Extends EnsLib.HTTP.OutboundAdapter
{

/// Send a POST to the configured Server, Port and URL, sending form data to the named form variables.
Method Post(Output pHttpResponse As %Net.HttpResponse, pFormVarNames As %String, pData...) As %Status
{

    quit ..SendFormDataArray(.pHttpResponse, "POST", ..GetRequest(), .pFormVarNames, .pData)
}

ClassMethod GetRequest() As %Net.HttpRequest
{
    set request = ##class(%Net.HttpRequest).%New()
    set request.ContentType = "application/json"
    quit request
}

}

And use it instead of default adapter.