Help with HttpClient

Posted by elton182 on 16-Jan-2019 01:44

Hi there, i'm using openedge 11.6.4 and I can't make this http get works.

```

/** This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means. **/
/*------------------------------------------------------------------------
File : get_applications.p
Purpose : Returns the list of applications from a PASOE server
Author(s) : pjudge
Created : Thu Oct 13 09:17:32 EDT 2016
Notes : * this is the equivalent of curl -X GET -v localhost:16680/.../ -u tomcat:tomcat
----------------------------------------------------------------------*/
block-level on error undo, throw.

using OpenEdge.Net.HTTP.ClientBuilder.
using OpenEdge.Net.HTTP.Credentials.
using OpenEdge.Net.HTTP.IHttpClient.
using OpenEdge.Net.HTTP.IHttpRequest.
using OpenEdge.Net.HTTP.RequestBuilder.
using OpenEdge.Net.URI.
using OpenEdge.Net.HTTP.IHttpResponse.
using Progress.Json.ObjectModel.JsonObject.
using Progress.Json.ObjectModel.JsonArray.

/* *************************** Session config *************************** */
/* OPTIONAL FOR DEBUG/TRACING
session:error-stack-trace = true.
log-manager:logging-level = 6.
log-manager:logfile-name = session:temp-dir + 'get_applications.log'.
log-manager:clear-log().
*/

/* *************************** Main Block *************************** */
define variable oClient as IHttpClient no-undo.
define variable oUri as URI no-undo.
define variable oReq as IHttpRequest no-undo.
define variable oResp as IHttpResponse no-undo.
define variable oCreds as Credentials no-undo.
define variable oJson as JsonArray no-undo.

oClient = ClientBuilder:Build():Client.

oUri = new URI('http', 'orient.innovareti.com.br', 80).
oUri:Path = '/approvedItems'.

oReq = RequestBuilder:Get(oUri)
:Request.

oResp = oClient:Execute(oReq).

assign oJson = cast(oResp:Entity, JsonArray).

/* do what you need to with the JSON here */

DEF VAR hTT AS HANDLE.
CREATE TEMP-TABLE hTT.
DEFINE VARIABLE l AS LOGICAL NO-UNDO.


l = hTT:READ-JSON("JsonArray", oJson).

DEFINE VARIABLE ix AS INTEGER NO-UNDO.


DEFINE VARIABLE hQuery AS HANDLE NO-UNDO.
DEFINE VARIABLE hBuffer AS HANDLE NO-UNDO.
DEFINE VARIABLE iNumFields AS INTEGER NO-UNDO.
DEFINE VARIABLE iLoop AS INTEGER NO-UNDO.

ASSIGN hBuffer = hTT:DEFAULT-BUFFER-HANDLE
iNumFields = hBuffer:NUM-FIELDS.

CREATE QUERY hQuery.

hQuery:SET-BUFFERS(hTT:DEFAULT-BUFFER-HANDLE).
hQuery:QUERY-PREPARE("FOR EACH " + hTT:NAME).
hQuery:QUERY-OPEN().
hQuery:GET-FIRST().

DO WHILE hQuery:QUERY-OFF-END = FALSE:
DO iLoop = 1 TO iNumFields:
MESSAGE
hBuffer:BUFFER-FIELD(iLoop):NAME
hBuffer:BUFFER-FIELD(iLoop):STRING-VALUE VIEW-AS ALERT-BOX.
END.
hQuery:GET-NEXT().
END.

hQuery:QUERY-CLOSE().

catch oError as Progress.Lang.Error :
message
oError:GetMessage(1) skip(2)
oError:CallStack
view-as alert-box.
end catch.

```

All Replies

This thread is closed