Unicode C
Unicode C
Example: Http.HttpFile method
Shows how to use the HttpFile method to send an HTTP POST request with the contents of a file as the request body. The example sends the following request:POST /api/v1/sites/123/deploys HTTP/1.1 Host: example.com Accept: */* Accept-Encoding: gzip Content-Type: application/zip Content-Length: 123456 [binary data bytes of data.zip]
Also see: Chilkat Http Default and Auto-Filled Headers
Chilkat Unicode C Downloads
#include <C_CkHttpW.h>
#include <C_CkHttpResponseW.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttpW http;
const wchar_t *localFilePath;
const wchar_t *url;
HCkHttpResponseW resp;
success = FALSE;
http = CkHttpW_Create();
localFilePath = L"C:/example/zips/data.zip";
url = L"https://example.com/api/v1/sites/123/deploys";
// Send a POST with the contents of the file in the binary HTTP request body.
resp = CkHttpResponseW_Create();
success = CkHttpW_HttpFile(http,L"POST",url,localFilePath,L"application/zip",resp);
if (success == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkHttpResponseW_Dispose(resp);
return;
}
wprintf(L"Response Status Code: %d\n",CkHttpResponseW_getStatusCode(resp));
wprintf(L"Response body:\n");
wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
CkHttpW_Dispose(http);
CkHttpResponseW_Dispose(resp);
}