Salesforce

How to send a string as the Request Body with the OpenEdge HTTP client

« Go Back

Information

 
TitleHow to send a string as the Request Body with the OpenEdge HTTP client
URL NameHow-to-send-a-string-as-the-Request-Body-when-using-the-OpenEdge-HTTP-client
Article Number000128393
EnvironmentProduct: OpenEdge
Version: 11.5.1 and later
OS: All supported platforms
Question/Problem Description
How to send a string as the Request Body when using the OpenEdge HTTP client.
How to populate the Request Body with a string when using the OpenEdge HTTP client.
Steps to Reproduce
Clarifying Information
Error Message
Defect Number
Enhancement Number
Cause
Resolution
You need to use the correct object type as the payload. In this case that's going to be an instance of a String object. Please make sure that you also set the correct ContentType on the request. For example to send the following HTTP POST messages from an OpenEdge client:
 
POST https://www.googleapis.com/oauth2/v3/token HTTP/1.1
Content-type: application/x-www-form-urlencoded
Host: www.googleapis.com

client_id=your_client_id&client_secret=your_client_secret&refresh_token=your_refresh_token&grant_type=refresh_token


You can use the following ABL code:
 
BLOCK-LEVEL ON ERROR UNDO, THROW.

USING OpenEdge.Core.String.
USING OpenEdge.Net.HTTP.ClientBuilder.
USING OpenEdge.Net.HTTP.IHttpRequest.
USING OpenEdge.Net.HTTP.IHttpResponse.
USING OpenEdge.Net.HTTP.RequestBuilder.
USING Progress.Json.ObjectModel.JsonObject. 

DEFINE VARIABLE httpUrl AS CHARACTER NO-UNDO.
DEFINE VARIABLE oRequest AS IHttpRequest NO-UNDO.
DEFINE VARIABLE oResponse AS IHttpResponse NO-UNDO.
DEFINE VARIABLE oRequestBody AS String NO-UNDO.
DEFINE VARIABLE oJsonEntity AS JsonObject NO-UNDO.
DEFINE VARIABLE JsonString AS LONGCHAR NO-UNDO.

SESSION:DEBUG-ALERT = TRUE.
httpUrl = "https://www.googleapis.com/oauth2/v3/token".

oRequestBody = new String('client_id=your_client_id&client_secret=your_client_secret&refresh_token=your_refresh_token&grant_type=refresh_token').

oRequest = RequestBuilder:Post("https://www.googleapis.com/oauth2/v3/token", oRequestBody)
:ContentType('application/x-www-form-urlencoded')
:AcceptJson()
:Request.

oResponse = ClientBuilder:Build():Client:Execute(oRequest).

MESSAGE
oResponse:StatusCode SKIP
oResponse:StatusReason SKIP
VIEW-AS ALERT-BOX.

oJsonEntity = CAST(oResponse:Entity, JsonObject).
oJsonEntity:Write(JsonString, TRUE).

MESSAGE STRING(JsonString)
VIEW-AS ALERT-BOX.
Workaround
Notes
References to Other Documentation:
Progress Article(s):
Getting started with HTTP client for OpenEdge
 
Keyword Phrase
Last Modified Date3/9/2023 6:34 PM

Powered by