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

Example: Http.HttpSReq method

Demonstrates how to call the HttpSReq method.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oReq
LOCAL oResp
LOCAL cRequestBody

nSuccess := 0

oHttp := CreateObject("Chilkat.Http")
oReq := CreateObject("Chilkat.HttpRequest")
oResp := CreateObject("Chilkat.HttpResponse")

//  Specify the details of the HTTP request.
oReq:HttpVerb := "POST"
oReq:ContentType := "application/json"
oReq:Path := "/echo_request_body.asp"

cRequestBody := '{"greeting":"Hello World"}'
oReq:LoadBodyFromString(cRequestBody, "utf-8")

//  Send a POST to https://chilkatsoft.com/echo_request_body.asp with a JSON request body.
nSuccess := oHttp:HttpSReq("chilkatsoft.com", 443, 1, oReq, oResp)
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oHttp:destroy()
    oReq:destroy()
    oResp:destroy()
    RETURN
ENDIF

? "Response Status Code: " + Str(oResp:StatusCode)

//  Examine the request we sent.
//  The LastHeader property stores the HTTP request header of the most recent request sent,
//  and in this instance, the response body mirrors the request body.
? oHttp:LastHeader
? oResp:BodyStr

//  Output:

//  POST /echo_request_body.asp HTTP/1.1
//  Host: chilkatsoft.com
//  Content-Type: application/json
//  Content-Length: 26
//  
//  {"greeting":"Hello World"}

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