Sample code for 30+ languages & platforms
Xbase++ Requires Chilkat v11.0.0+

Example: Http.HttpReq method

Demonstrates how to call the HttpReq method.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oJson
LOCAL oReq
LOCAL oResp

nSuccess := 0

oHttp := CreateObject("Chilkat.Http")
nSuccess := 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" }

oJson := CreateObject("Chilkat.JsonObject")
oJson:UpdateString("name", "Harry")
oJson:UpdateString("state", "FL")

//  Specify the details of the request
oReq := CreateObject("Chilkat.HttpRequest")

oReq:HttpVerb := "POST"
oReq:ContentType := "application/json"
oReq:LoadBodyFromString(oJson:Emit(), "utf-8")

//  Send the charset attribute in the HTTP request header.
oReq:SendCharset := 1
oReq: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).

oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpReq("https://www.chilkatsoft.com/echo_request_body.asp", oReq, oResp)
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oHttp:destroy()
    oJson:destroy()
    oReq:destroy()
    oResp:destroy()
    RETURN
ENDIF

//  Examine the HTTP request header we sent:
? oHttp:LastHeader

//  The response body contains the raw content of the HTTP request body we sent.
? oResp: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"}

oHttp:destroy()
oJson:destroy()
oReq:destroy()
oResp:destroy()