Visual FoxPro
Visual FoxPro
Capture the Composed REST Request for Debugging
See more REST Examples
Demonstrates Rest.GetLastDebugRequest, which copies the fully composed HTTP request (request line, headers, and body) into a BinData. The example builds a two-part multipart request so the captured output shows the multipart boundaries, part headers, and part bodies. This works when the DebugMode property was enabled while the request was composed.
Background. When DebugMode is enabled, Chilkat builds the request but does not transmit it, so GetLastDebugRequest can reveal the exact bytes that would be sent. Inspecting the composed request is valuable for diagnosing API problems.
Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loRest
LOCAL lnBTls
LOCAL lnBAutoReconnect
LOCAL loBdRequest
LOCAL lcRequestText
lnSuccess = 0
loRest = CreateObject('Chilkat.Rest')
lnBTls = 1
lnBAutoReconnect = 1
lnSuccess = loRest.Connect("example.com",443,lnBTls,lnBAutoReconnect)
IF (lnSuccess = 0) THEN
? loRest.LastErrorText
RELEASE loRest
CANCEL
ENDIF
* Enable debug mode so the fully composed HTTP request is captured instead of being sent.
loRest.DebugMode = 1
* Build a multipart request with two parts. The captured debug output will show the multipart
* boundaries, part headers, and part bodies.
loRest.PartSelector = "1"
loRest.AddHeader("Content-Type","text/plain")
loRest.AddHeader("Content-Disposition",'form-data; name="field1"')
lnSuccess = loRest.SetMultipartBodyString("value1")
IF (lnSuccess = 0) THEN
? loRest.LastErrorText
RELEASE loRest
CANCEL
ENDIF
loRest.PartSelector = "2"
loRest.AddHeader("Content-Type","application/json")
loRest.AddHeader("Content-Disposition",'form-data; name="metadata"')
lnSuccess = loRest.SetMultipartBodyString('{ "active": true }')
IF (lnSuccess = 0) THEN
? loRest.LastErrorText
RELEASE loRest
CANCEL
ENDIF
* Compose the multipart request. In debug mode the request is built but not transmitted.
lnSuccess = loRest.SendReqMultipart("POST","/api/upload")
IF (lnSuccess = 0) THEN
? loRest.LastErrorText
RELEASE loRest
CANCEL
ENDIF
* Copy the composed request (request line, headers, and multipart body that would be sent) into a
* BinData, then view it as text.
loBdRequest = CreateObject('Chilkat.BinData')
loRest.GetLastDebugRequest(loBdRequest)
lcRequestText = loBdRequest.GetString("utf-8")
IF (loBdRequest.LastMethodSuccess = 0) THEN
? loBdRequest.LastErrorText
RELEASE loRest
RELEASE loBdRequest
CANCEL
ENDIF
? lcRequestText
RELEASE loRest
RELEASE loBdRequest