Unicode C
Unicode C
Set a Multipart Part Body from a String
See more REST Examples
Demonstrates Rest.SetMultipartBodyString, which sets the text body of the currently selected multipart part.
Background. A multipart request is assembled part by part: the part selector chooses the part being built, header fields describe it, and a SetMultipartBody method supplies its content. The request is then sent with a multipart send or full-request method.
Chilkat Unicode C Downloads
#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;
}
// Select the multipart part to build, and set its header fields.
CkRestW_putPartSelector(rest,L"1");
CkRestW_AddHeader(rest,L"Content-Disposition",L"form-data; name=\"field1\"");
CkRestW_AddHeader(rest,L"Content-Type",L"text/plain");
// Set the text body of the selected multipart part.
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 part(s).
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);
}