Skip to Content
0
Feb 10, 2016 at 08:56 PM

ABAP CL_HTTP_CLIENT REST JSON issue

13476 Views

We have a need to connect to an external HTTPS REST service from ABAP that uses JSON.


We are using straight ABAP via SAPGui, not Eclipse, and we are not on 7.4 yet so I can't use the new standard SAP JSON class.


I downloaded and installed the ZJSON stuff, but I'm having trouble finding clear examples describing how it should be used.


So far, I am calling the CL_HTTP_CLIENT class CREATE_BY_DESTINATION method to open a connection to the external service using Basic Authentication. They have given us a base URL with various method subpaths depending upon the specific function we need to call.


My trouble spot has been trying to call their API methods where I need to pass parameters but I'm having trouble with the HTTP / REST / JSON syntax using the ABAP CL_HTTP_CLIENT class.

I am calling CL_HTTP_CLIENT->REQUEST->SET_HEADER_FIELD to set the header values:

'~server_protocol' = 'HTTP/1.1'

'Accept' = 'application/json'

'Content-Type' = 'application/json; charset=utf-8'

I am calling CL_HTTP_CLIENT->REQUEST->SET_METHOD to set the request method to "POST"

I am also calling CL_HTTP_UTILITY=>SET_REQUEST_URI to set the full method path (after the base URL), including the specific method we need to use.

I have tried setting the required method parameters as form fields, but I think they need it to be in JSON format.

As a test, I hardcoded what they are expecting and called CL_HTTP_CLIENT->REQUEST->SET_CDATA but their server returns a very length HTML page instead of the expected return parameters wrapping in JSON syntax.

Am I on the right track?? Does the CL_HTTP_CLIENT->REQUEST->SET_CDATA (or SET_DATA) method place the specified content into the HTTP REST "payload" or should I be doing something else?

Thank you so much for any assistance you can provide.

Bryan