PowerBuilder
PowerBuilder
Example: Http.HttpReq method
Demonstrates how to call the HttpReq method.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_Json
oleobject loo_Req
oleobject loo_Resp
li_Success = 0
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
li_Success = 0
// This example will send an HTTP POST with the body of the HTTP request containing JSON.
// Create the following JSON: { "name": "Harry", "state": "FL" }
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.UpdateString("name","Harry")
loo_Json.UpdateString("state","FL")
// Specify the details of the request
loo_Req = create oleobject
li_rc = loo_Req.ConnectToNewObject("Chilkat.HttpRequest")
loo_Req.HttpVerb = "POST"
loo_Req.ContentType = "application/json"
loo_Req.LoadBodyFromString(loo_Json.Emit(),"utf-8")
// Send the charset attribute in the HTTP request header.
loo_Req.SendCharset = 1
loo_Req.Charset = "utf-8"
// Send the POST
// You can send the POST to the URL below.
// The response will contain the raw body of the request that was sent.
// (i.e. everything except the HTTP request header).
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")
li_Success = loo_Http.HttpReq("https://www.chilkatsoft.com/echo_request_body.asp",loo_Req,loo_Resp)
if li_Success = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Json
destroy loo_Req
destroy loo_Resp
return
end if
// Examine the HTTP request header we sent:
Write-Debug loo_Http.LastHeader
// The response body contains the raw content of the HTTP request body we sent.
Write-Debug loo_Resp.BodyStr
// Sample output:
// POST /echo_request_body.asp HTTP/1.1
// Host: www.chilkatsoft.com
// Content-Type: application/json; charset=utf-8
// Content-Length: 29
//
//
// {"name":"Harry","state":"FL"}
destroy loo_Http
destroy loo_Json
destroy loo_Req
destroy loo_Resp