Sample code for 30+ languages & platforms
DataFlex

Example: Http.HttpReq method

Demonstrates how to call the HttpReq method.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoHttp
    Handle hoJson
    Variant vReq
    Handle hoReq
    Variant vResp
    Handle hoResp
    String sTemp1

    Move False To iSuccess

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End
    Move False To iSuccess

    // This example will send an HTTP POST with the body of the HTTP request containing JSON.

    // Create the following JSON: { "name": "Harry", "state": "FL" }

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "name" "Harry" To iSuccess
    Get ComUpdateString Of hoJson "state" "FL" To iSuccess

    // Specify the details of the request
    Get Create (RefClass(cComChilkatHttpRequest)) To hoReq
    If (Not(IsComObjectCreated(hoReq))) Begin
        Send CreateComObject of hoReq
    End

    Set ComHttpVerb Of hoReq To "POST"
    Set ComContentType Of hoReq To "application/json"
    Get ComEmit Of hoJson To sTemp1
    Get ComLoadBodyFromString Of hoReq sTemp1 "utf-8" To iSuccess

    // Send the charset attribute in the HTTP request header.
    Set ComSendCharset Of hoReq To True
    Set ComCharset Of hoReq To "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).

    Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
    If (Not(IsComObjectCreated(hoResp))) Begin
        Send CreateComObject of hoResp
    End
    Get pvComObject of hoReq to vReq
    Get pvComObject of hoResp to vResp
    Get ComHttpReq Of hoHttp "https://www.chilkatsoft.com/echo_request_body.asp" vReq vResp To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Examine the HTTP request header we sent:
    Get ComLastHeader Of hoHttp To sTemp1
    Showln sTemp1

    // The response body contains the raw content of the HTTP request body we sent.
    Get ComBodyStr Of hoResp To sTemp1
    Showln sTemp1

    // 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"}


End_Procedure