DataFlex
DataFlex
Demonstrate the REST FullRequestNoBodySb Method
See more REST Examples
Demonstrates the FullRequestNoBodySb method, which sends an HTTP request with no body and receives the response in a Chilkat StringBuilder object.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoRest
Boolean iBTls
Integer iPort
Boolean iBAutoReconnect
Variant vSbJson
Handle hoSbJson
String sTemp1
Integer iTemp1
Move False To iSuccess
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatRest)) To hoRest
If (Not(IsComObjectCreated(hoRest))) Begin
Send CreateComObject of hoRest
End
// Connect to the REST server.
Move True To iBTls
Move 443 To iPort
Move True To iBAutoReconnect
Get ComConnect Of hoRest "chilkatsoft.com" iPort iBTls iBAutoReconnect To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
// Send an HTTP request with no body...
// An HTTP request with no body is a simple HTTP request that is typically a GET or DELETE.
// (POST and PUT requests typically have a request body.)
// The GET method is used to request data from a specified resource,
// and it does not have a request body. Here's an example of an HTTP GET request:
//
// GET /api/data HTTP/1.1
// Host: example.com
// Accept: application/json
//
// - The HTTP method (also known as the verb) is "GET," indicating that the client wants to retrieve data from the specified resource.
// - The request path is "/api/data," representing the resource the client wants to access.
// - The "Host" header specifies the hostname of the server being requested. Chilkat automatically adds it.
// - The "Accept" header indicates the media type (MIME type) that the client can understand and would like to receive in the response. In this case, it specifies that the client prefers to receive data in JSON format.
//
// Since the GET method does not have a request body, the request ends after the headers.
// The server will process the request, retrieve the requested data (if available), and respond with an HTTP response
// containing the requested data (if any) in the message body.
//
// The body of the HTTP response is written to the StringBuilder object (overwriting whatever content the StringBuilder may have already contained).
//
Get ComAddHeader Of hoRest "Accept" "application/json" To iSuccess
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbJson
If (Not(IsComObjectCreated(hoSbJson))) Begin
Send CreateComObject of hoSbJson
End
Get pvComObject of hoSbJson to vSbJson
Get ComFullRequestNoBodySb Of hoRest "GET" "/testData/helloWorld.json" vSbJson To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComResponseStatusCode Of hoRest To iTemp1
Showln "Response status code = " iTemp1
Showln "Response body:"
Get ComGetAsString Of hoSbJson To sTemp1
Showln sTemp1
End_Procedure