Sample code for 30+ languages & platforms
DataFlex

Send a Form-URL-Encoded REST Request

See more REST Examples

Demonstrates Rest.FullRequestFormUrlEncoded, which sends an application/x-www-form-urlencoded request. The body is built from the query parameters added to the object, and the response body is returned as text.

Background. For a form-url-encoded request the accumulated parameters become the request body rather than the URL query string. This matches the encoding used by HTML form POSTs.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoRest
    Boolean iBTls
    Boolean iBAutoReconnect
    String sResponseText
    String sTemp1
    Boolean bTemp1

    Move False To iSuccess

    Get Create (RefClass(cComChilkatRest)) To hoRest
    If (Not(IsComObjectCreated(hoRest))) Begin
        Send CreateComObject of hoRest
    End
    Move True To iBTls
    Move True To iBAutoReconnect
    Get ComConnect Of hoRest "example.com" 443 iBTls iBAutoReconnect To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  The application/x-www-form-urlencoded body is built from the query parameters added to the object.
    Get ComAddQueryParam Of hoRest "username" "alice" To iSuccess
    Get ComAddQueryParam Of hoRest "action" "login" To iSuccess

    //  Send the form-url-encoded request.  The parameters become the request body rather than the URL
    //  query string.
    Get ComFullRequestFormUrlEncoded Of hoRest "POST" "/api/login" To sResponseText
    Get ComLastMethodSuccess Of hoRest To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln sResponseText


End_Procedure