Sample code for 30+ languages & platforms
B4X

POST application/x-www-form-urlencoded using REST API

See more REST Examples

Demonstrates how to send a POST with query params (x-www-form-urlencoded) using the Chilkat REST object.

Chilkat B4X Downloads

B4X
Dim success As Boolean = False

'  This example requires the Chilkat API to have been previously unlocked.
'  See Global Unlock Sample for sample code.

Dim rest As ChilkatRest
rest.Initialize("rest")

'  This example will send to https://www.chilkatsoft.com/echoPost.asp

'  Make the initial connection (without sending a request yet).
Dim bTls As Boolean = True
Dim port As Int = 443
Dim bAutoReconnect As Boolean = True
success = rest.Connect("www.chilkatsoft.com", port, bTls, bAutoReconnect)
If success <> True Then
    Log(rest.LastErrorText)
    Return
End If


'  Provide query params.
rest.AddQueryParam("firstName", "John")
rest.AddQueryParam("lastName", "Doe")
rest.AddQueryParam("company", "Bisco Bits Ltd.")

Dim responseStr As String = rest.FullRequestFormUrlEncoded("POST", "/echoPost.asp")
If rest.LastMethodSuccess <> True Then
    Log(rest.LastErrorText)
    Return
End If


'  When successful, the response status code will equal 200.
If rest.ResponseStatusCode <> 200 Then
    '  Examine the request/response to see what happened.
    Log("response status code = " & rest.ResponseStatusCode)
    Log("response status text = " & rest.ResponseStatusText)
    Log("response header: " & rest.ResponseHeader)
    Log("response body (if any): " & responseStr)
    Log("---")
    Log("LastRequestStartLine: " & rest.LastRequestStartLine)
    Log("LastRequestHeader: " & rest.LastRequestHeader)
    Return
End If


Log(responseStr)
Log("Success.")