Sample code for 30+ languages & platforms
Unicode C

Clear a REST Response Body Stream Destination

See more REST Examples

Demonstrates Rest.ClearResponseBodyStream, which removes a response-stream destination previously configured with SetResponseBodyStream.

The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.

Background. Clearing the destination restores normal behavior, in which the full-request convenience methods return the response body rather than streaming it.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkRestW.h>
#include <C_CkStreamW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkRestW rest;
    BOOL bTls;
    BOOL bAutoReconnect;
    HCkStreamW respStream;
    BOOL bAutoSetCharset;
    int expectedStatus;

    success = FALSE;

    rest = CkRestW_Create();
    bTls = TRUE;
    bAutoReconnect = TRUE;
    success = CkRestW_Connect(rest,L"example.com",443,bTls,bAutoReconnect);
    if (success == FALSE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        return;
    }

    //  The file paths are relative to the application's current working directory.  Absolute paths
    //  may also be used.  Supply the paths appropriate to your own environment.

    respStream = CkStreamW_Create();
    CkStreamW_putSinkFile(respStream,L"qa_output/response_body.dat");
    bAutoSetCharset = TRUE;
    expectedStatus = 200;
    success = CkRestW_SetResponseBodyStream(rest,expectedStatus,bAutoSetCharset,respStream);
    if (success == FALSE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkStreamW_Dispose(respStream);
        return;
    }

    //  Clear the response-stream destination previously configured, so subsequent full-request calls
    //  return the response body normally instead of streaming it.
    CkRestW_ClearResponseBodyStream(rest);

    wprintf(L"Response body streaming cleared.\n");


    CkRestW_Dispose(rest);
    CkStreamW_Dispose(respStream);

    }