PureBasic
PureBasic
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 PureBasic Downloads
IncludeFile "CkRest.pb"
Procedure ChilkatExample()
success.i = 0
rest.i = CkRest::ckCreate()
If rest.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
bTls.i = 1
bAutoReconnect.i = 1
success = CkRest::ckConnect(rest,"example.com",443,bTls,bAutoReconnect)
If success = 0
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
ProcedureReturn
EndIf
; The application/x-www-form-urlencoded body is built from the query parameters added to the object.
CkRest::ckAddQueryParam(rest,"username","alice")
CkRest::ckAddQueryParam(rest,"action","login")
; Send the form-url-encoded request. The parameters become the request body rather than the URL
; query string.
responseText.s = CkRest::ckFullRequestFormUrlEncoded(rest,"POST","/api/login")
If CkRest::ckLastMethodSuccess(rest) = 0
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
ProcedureReturn
EndIf
Debug responseText
CkRest::ckDispose(rest)
ProcedureReturn
EndProcedure