Try OpenEdge Now
skip to main content
Programming Interfaces
Input/Output Processes : Making HTTP(S) requests from ABL applications : Basic request-response functionality : OpenEdge.Net.HTTP.IHttpResponse
 
OpenEdge.Net.HTTP.IHttpResponse
Once a request successfully executes (note that success is defined as a successful round trip, however a successful request may return undesired or unexpected results), an IHttpResponse object is returned to the caller. The two most important pieces of data this object returns are the StatusCode and the Entity properties.
The Entity property has a defined type of Progress.Lang.Object although the type of the object contained in it is usually something more specialized. The response will convert text received by an HTTP client into a JsonConstruct, OpenEdge.Core.String or some other type, depending on the ContentType of the response.
The StatusCode property indicates the result of the request. These values can be enumerated by OpenEdge.Net.HTTP.StatusCodeEnum, which is based on http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.1.1

Examples

The sample code below retrieves the Entity and writes it to disk in the correct format based on the type of the returned Entity. We can also use the response's ContentType property to perform similar operations.
Extracting typed data from a response
USING Progress.Json.ObjectModel.JsonObject.
USING Progress.Json.ObjectModel.ObjectModelParser.
USING Progress.Lang.Object.USING OpenEdge.Core.WidgetHandle.
USING OpenEdge.Core.String.USING OpenEdge.Net.HTTP.IHttpRequest.
USING OpenEdge.Net.HTTP.IHttpResponse.
USING OpenEdge.Net.HTTP.ClientBuilder.
USING OpenEdge.Net.HTTP.RequestBuilder.

DEFINE VARIABLE oRequest AS IHttpRequest NO-UNDO.
DEFINE VARIABLE oResponse AS IHttpResponse NO-UNDO.
DEFINE VARIABLE oEntity AS Object NO-UNDO.
DEFINE VARIABLE lcHTML AS LONGCHAR NO-UNDO.
DEFINE VARIABLE hXmlDoc AS HANDLE NO-UNDO.

oRequest = RequestBuilder:Get('http://localhost:9090/oem/resources')
:Request.

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

IF TYPE-OF(oEntity, JsonObject) THEN
CAST(oEntity, JsonObject):WriteFile('temp/entity.json', true).
ELSE
IF TYPE-OF(oEntity, WidgetHandle) THEN
DO:
hXmlDoc = CAST(oEntity, WidgetHandle):Value.
hXmlDoc:save('file', 'temp/entity.xml').
END.
ELSE
DO:
IF TYPE-OF(oEntity, String) THEN
lcHTML = CAST(oEntity, String):Value.
ELSE
lcHTML = oEntity:ToString().

/* Change extension per the Response's ContentType */
CASE oResponse:ContentType:
WHEN 'application/json' THEN
COPY-LOB lcHTML TO FILE 'temp/entity.json'.
WHEN 'text/html' THEN
COPY-LOB lcHTML TO FILE 'temp/entity.html'.
OTHERWISE
COPY-LOB lcHTML TO FILE 'temp/entity.txt'.
END CASE.
END.
The code sample below retrieves the StatusCode of a request and displays it as a message in an alert box.
Status codes
USING OpenEdge.Net.HTTP.IHttpRequest.
USING OpenEdge.Net.HTTP.IHttpResponse.
USING OpenEdge.Net.HTTP.ClientBuilder.

DEFINE VARIABLE oRequest AS IHttpRequest NO-UNDO.
DEFINE VARIABLE oResponse AS IHttpResponse NO-UNDO.

oResponse = ClientBuilder:Build():Client:Execute(oRequest).
MESSAGE
oResponse:StatusCode SKIP
oResponse:StatusReason SKIP
VIEW-AS ALERT-BOX.