Forum Post: RE: OpenEdge.Net.HTTP infinite Looping

Status
Not open for further replies.
C

CMI

Guest
I think I figured out where I'm going wrong. The servers response is in the Response:Entity public property. See the code below for my revised version. USING OpenEdge.Net.HTTP.*. USING OpenEdge.Core.String. USING OpenEdge.Core.WidgetHandle. USING Progress.Lang.Object. USING Progress.Json.ObjectModel.JsonObject. DEFINE VARIABLE oRequest AS IhttpRequest NO-UNDO. DEFINE VARIABLE oResponse AS IhttpResponse NO-UNDO. DEFINE VARIABLE httpUrl AS CHARACTER NO-UNDO. DEFINE VARIABLE oEntity AS OBJECT NO-UNDO. DEFINE VARIABLE XMLDocument AS HANDLE NO-UNDO. DEFINE VARIABLE payload AS LONGCHAR NO-UNDO. DEFINE VARIABLE HttpHeaders AS CLASS HttpHeader NO-UNDO EXTENT. httpUrl = "http://www.progress.com". oRequest = RequestBuilder:Get(httpUrl):Request. oResponse = ClientBuilder:Build():Client:Execute(oRequest). /** Debug HTTP Response Headers **/ DEFINE VARIABLE iNumHeaders AS INTEGER NO-UNDO. DEFINE VARIABLE iHeaderEntry AS INTEGER NO-UNDO. iNumHeaders = oResponse:GetHeaders(OUTPUT HttpHeaders). DO iHeaderEntry = 1 TO iNumHeaders: MESSAGE HttpHeaders[iHeaderEntry]:Name HttpHeaders[iHeaderEntry]:Value. END. MESSAGE 'Status:' oResponse:StatusCode oResponse:StatusReason SKIP 'Version:' oResponse:Version SKIP 'Character Encoding:' oResponse:CharacterEncoding SKIP 'Transfer Encoding:' oResponse:TransferEncoding SKIP 'Content Length:' oResponse:ContentLength SKIP 'MD5' STRING(oResponse:ContentMD5) view-as alert-box info TITLE ''. /** Get the payload.**/ oEntity = oResponse:Entity. CASE TRUE: WHEN TYPE-OF(oEntity, JsonObject) THEN CAST(oEntity,JsonObject):WriteFile('temp/payload.json', true). WHEN TYPE-OF(oEntity, WidgetHandle) THEN DO: MESSAGE 'Lookes LIke an XML document'. XMLDocument = CAST(oEntity, WidgetHandle ):Value. XMLDocument:Save('file','temp/payload.xml'). END. OTHERWISE DO: IF TYPE-OF(oEntity, String) THEN payload = CAST(oEntity, String):Value. ELSE payload = oEntity:ToString(). CASE oResponse:ContentType: WHEN 'application/xml' THEN COPY-LOB payload to file 'temp/payload.xml'. WHEN 'application/json' THEN COPY-LOB payload to file 'temp/payload.json'. WHEN 'text/html' THEN COPY-LOB payload to file 'temp/payload.html'. OTHERWISE COPY-LOB payload to file 'temp/payload.txt'. END CASE. END. END CASE.

Continue reading...
 
Status
Not open for further replies.
Top