How to do UploadData using WebClient?

Posted by goo on 11-Jun-2019 13:57

11.7

I am trying to send a PATCH to a REST service.

def var sendData as "System.Byte[]" no-undo.

 oUri = new System.Uri(wc:BaseAddress + 'tasks').

sendData = System.Text.Encoding.UTF8:GetBytes(ipData).

wc:UploadData(oUri,'PATCH',sendData).

How do I do this:

sendData = System.Text.Encoding.UTF8:GetBytes(ipData). ??? 

//Geir Otto

All Replies

Posted by Peter Judge on 11-Jun-2019 14:42

That depends on what ipData is. The ABL HTTP client will convert many 'strongly typed objects' to an HTTP message (in bytes).
 
The code below is an example of how you'd send a PATCH request using the ABL HTTP client.
 
using OpenEdge.Net.HTTP.IHttpRequest.
using OpenEdge.Net.HTTP.IHttpResponse.
using OpenEdge.Net.HTTP.IHttpClient.
using OpenEdge.Net.HTTP.ClientBuilder.
using OpenEdge.Net.HTTP.RequestBuilder.
using Progress.Json.ObjectModel.JsonObject.
 
define variable req as IHttpRequest no-undo.
define variable resp as IHttpResponse no-undo.
define variable hc as IHttpClient no-undo.
define variable jsonData as JsonObject no-undo.
 
hc = ClientBuilder:Build():Client.
 
req = RequestBuilder:Patch(wc:BaseAddress + '/tasks',
                           ipdata,                         // this must be an OOABL object
                           'application/blah-blah')      // content type of the data being sent
                    :Request.
 
resp = hc:Execute(req).
 
if resp:StatusCode eq 200 then
// do stuff with the response
case resp:ContentType:
    when 'application/json' then assign jsonData = cast(resp:Entity, JsonObject).
end case.
 
 
 
 

Posted by goo on 11-Jun-2019 14:50

Got it to work....

   def var sendData as "System.Byte[]" no-undo.

   def var responseArray as "System.Byte[]" no-undo.

   def var UTF8 as System.Text.Encoding no-undo.

   UTF8 = System.Text.Encoding:UTF8.

   oUri = new System.Uri(wc:BaseAddress + 'tasks' + '?taskAssignmentId=' + ipAssignmentId + '&newStatus=' + ipNewStatus).

   sendData = UTF8:GetBytes(ipData).

   responseArray = wc:UploadData(oUri,'PATCH',sendData).

   lc = UTF8:GetString(responseArray, 0, responseArray:Length).

   RETURN lc.

This thread is closed