C
C
Transition from Http.SynchronousRequest to Http.HttpSReq
Provides instructions for replacing deprecated SynchronousRequest method calls with HttpSReq.Chilkat C Downloads
#include <C_CkHttp.h>
#include <C_CkHttpRequest.h>
#include <C_CkHttpResponse.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttp http;
const char *domain;
int port;
int tls;
HCkHttpRequest req;
HCkHttpResponse responseObj;
HCkHttpResponse responseOut;
success = FALSE;
http = CkHttp_Create();
domain = "example.com";
port = 443;
tls = TRUE;
req = CkHttpRequest_Create();
CkHttpRequest_putHttpVerb(req,"POST");
CkHttpRequest_putPath(req,"/some/path");
CkHttpRequest_putContentType(req,"application/x-www-form-urlencoded");
CkHttpRequest_AddParam(req,"firstName","Matt");
CkHttpRequest_AddParam(req,"lastName","Smith");
// ------------------------------------------------------------------------
// The SynchronousRequest method is deprecated:
responseObj = CkHttp_SynchronousRequest(http,domain,port,tls,req);
if (CkHttp_getLastMethodSuccess(http) == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkHttpRequest_Dispose(req);
return;
}
// ...
// ...
CkHttpResponse_Dispose(responseObj);
// ------------------------------------------------------------------------
// Do the equivalent using HttpSReq.
// Your application creates a new, empty HttpResponse object which is passed
// in the last argument and filled upon success.
responseOut = CkHttpResponse_Create();
success = CkHttp_HttpSReq(http,domain,port,tls,req,responseOut);
if (success == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkHttpRequest_Dispose(req);
CkHttpResponse_Dispose(responseOut);
return;
}
CkHttp_Dispose(http);
CkHttpRequest_Dispose(req);
CkHttpResponse_Dispose(responseOut);
}