Xbase++
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oRest
LOCAL nBTls
LOCAL nPort
LOCAL nBAutoReconnect
LOCAL cResponseStr
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oRest := CreateObject("Chilkat.Rest")
// This example will send to https://www.chilkatsoft.com/echoPost.asp
// Make the initial connection (without sending a request yet).
nBTls := 1
nPort := 443
nBAutoReconnect := 1
nSuccess := oRest:Connect("www.chilkatsoft.com", nPort, nBTls, nBAutoReconnect)
IF (nSuccess != 1)
? oRest:LastErrorText
oRest:destroy()
RETURN
ENDIF
// Provide query params.
oRest:AddQueryParam("firstName", "John")
oRest:AddQueryParam("lastName", "Doe")
oRest:AddQueryParam("company", "Bisco Bits Ltd.")
cResponseStr := oRest:FullRequestFormUrlEncoded("POST", "/echoPost.asp")
IF (oRest:LastMethodSuccess != 1)
? oRest:LastErrorText
oRest:destroy()
RETURN
ENDIF
// When successful, the response status code will equal 200.
IF (oRest:ResponseStatusCode != 200)
// Examine the request/response to see what happened.
? "response status code = " + Str(oRest:ResponseStatusCode)
? "response status text = " + oRest:ResponseStatusText
? "response header: " + oRest:ResponseHeader
? "response body (if any): " + cResponseStr
? "---"
? "LastRequestStartLine: " + oRest:LastRequestStartLine
? "LastRequestHeader: " + oRest:LastRequestHeader
oRest:destroy()
RETURN
ENDIF
? cResponseStr
? "Success."
oRest:destroy()