Sample code for 30+ languages & platforms
Unicode C

Send a Multipart REST Request

See more REST Examples

Demonstrates Rest.FullRequestMultipart, which sends a complete multipart request using the parts configured on the object, then returns the response body as text.

Background. Each multipart part is built by selecting it with the part selector, adding its header fields, and setting its body. FullRequestMultipart then assembles and sends all configured parts as a single multipart request.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkRestW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkRestW rest;
    BOOL bTls;
    BOOL bAutoReconnect;
    const wchar_t *responseText;

    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;
    }

    //  Configure a multipart request part before sending.  PartSelector selects the part being built,
    //  and the header fields and body apply to that part.
    CkRestW_putPartSelector(rest,L"1");
    CkRestW_AddHeader(rest,L"Content-Type",L"text/plain");
    CkRestW_AddHeader(rest,L"Content-Disposition",L"form-data; name=\"field1\"");
    success = CkRestW_SetMultipartBodyString(rest,L"value1");
    if (success == FALSE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        return;
    }

    //  Send the multipart request using the configured parts.  The response body is returned as text.
    responseText = CkRestW_fullRequestMultipart(rest,L"POST",L"/api/upload");
    if (CkRestW_getLastMethodSuccess(rest) == FALSE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        return;
    }

    wprintf(L"%s\n",responseText);


    CkRestW_Dispose(rest);

    }