C
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 C Downloads
#include <C_CkRest.h>
void ChilkatSample(void)
{
BOOL success;
HCkRest rest;
BOOL bTls;
BOOL bAutoReconnect;
const char *responseText;
success = FALSE;
rest = CkRest_Create();
bTls = TRUE;
bAutoReconnect = TRUE;
success = CkRest_Connect(rest,"example.com",443,bTls,bAutoReconnect);
if (success == FALSE) {
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
return;
}
// Select the multipart part to build, and set its header fields.
CkRest_putPartSelector(rest,"1");
CkRest_AddHeader(rest,"Content-Disposition","form-data; name=\"field1\"");
CkRest_AddHeader(rest,"Content-Type","text/plain");
// Set the text body of the selected multipart part.
success = CkRest_SetMultipartBodyString(rest,"value1");
if (success == FALSE) {
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
return;
}
// Send the multipart request using the configured part(s).
responseText = CkRest_fullRequestMultipart(rest,"POST","/api/upload");
if (CkRest_getLastMethodSuccess(rest) == FALSE) {
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
return;
}
printf("%s\n",responseText);
CkRest_Dispose(rest);
}