Visual Basic 6.0
Visual Basic 6.0
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 Basic 6.0 Downloads
Dim success As Long
success = 0
Dim rest As New ChilkatRest
Dim bTls As Long
bTls = 1
Dim bAutoReconnect As Long
bAutoReconnect = 1
success = rest.Connect("example.com",443,bTls,bAutoReconnect)
If (success = 0) Then
Debug.Print rest.LastErrorText
Exit Sub
End If
' Enable debug mode so the fully composed HTTP request is captured instead of being sent.
rest.DebugMode = 1
' Build a multipart request with two parts. The captured debug output will show the multipart
' boundaries, part headers, and part bodies.
rest.PartSelector = "1"
success = rest.AddHeader("Content-Type","text/plain")
success = rest.AddHeader("Content-Disposition","form-data; name=""field1""")
success = rest.SetMultipartBodyString("value1")
If (success = 0) Then
Debug.Print rest.LastErrorText
Exit Sub
End If
rest.PartSelector = "2"
success = rest.AddHeader("Content-Type","application/json")
success = rest.AddHeader("Content-Disposition","form-data; name=""metadata""")
success = rest.SetMultipartBodyString("{ ""active"": true }")
If (success = 0) Then
Debug.Print rest.LastErrorText
Exit Sub
End If
' Compose the multipart request. In debug mode the request is built but not transmitted.
success = rest.SendReqMultipart("POST","/api/upload")
If (success = 0) Then
Debug.Print rest.LastErrorText
Exit Sub
End If
' Copy the composed request (request line, headers, and multipart body that would be sent) into a
' BinData, then view it as text.
Dim bdRequest As New ChilkatBinData
success = rest.GetLastDebugRequest(bdRequest)
Dim requestText As String
requestText = bdRequest.GetString("utf-8")
If (bdRequest.LastMethodSuccess = 0) Then
Debug.Print bdRequest.LastErrorText
Exit Sub
End If
Debug.Print requestText