C
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 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;
}
// Configure a multipart request part before sending. PartSelector selects the part being built,
// and the header fields and body apply to that part.
CkRest_putPartSelector(rest,"1");
CkRest_AddHeader(rest,"Content-Type","text/plain");
CkRest_AddHeader(rest,"Content-Disposition","form-data; name=\"field1\"");
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 parts. The response body is returned as text.
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);
}