PowerBuilder
PowerBuilder
Send a REST Request with a Text Body
See more REST Examples
Demonstrates Rest.FullRequestString, a convenience method that sends a complete request whose text body (such as JSON, XML, or plain text) is supplied directly, then reads and returns the response body as text.
Background. The full-request convenience methods perform the entire request/response exchange in a single call. FullRequestString is well suited to typical JSON or XML API calls where the body fits comfortably in a string.
Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Rest
integer li_BTls
integer li_BAutoReconnect
string ls_JsonBody
string ls_ResponseText
li_Success = 0
loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")
if li_rc < 0 then
destroy loo_Rest
MessageBox("Error","Connecting to COM object failed")
return
end if
li_BTls = 1
li_BAutoReconnect = 1
li_Success = loo_Rest.Connect("example.com",443,li_BTls,li_BAutoReconnect)
if li_Success = 0 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
return
end if
// Send a complete request whose text body is supplied directly, such as JSON. The response body is
// read as text and returned. The 1st argument is the HTTP verb, the 2nd is the URI path, and the
// 3rd is the request body.
loo_Rest.AddHeader("Content-Type","application/json")
ls_JsonBody = "{ ~"name~": ~"example~", ~"active~": true }"
ls_ResponseText = loo_Rest.FullRequestString("POST","/api/items",ls_JsonBody)
if loo_Rest.LastMethodSuccess = 0 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
return
end if
Write-Debug ls_ResponseText
destroy loo_Rest