C++ Rewrite/update a function to work with HTTPS and with CURL library Version 7.28.0. Now works with HTTP.
Budget: $10 – $30 USD
Hello guys,
I am looking for a C++ expert who it is able to complete a task: add HTTPs support for an existing C++ project.
The current project uses CURL library Version 7.28.0 (10 Oct 2012) linked statically to a Visual Studio 2008 project.
The current project sends data to the server using HTTP and the function that does that is listed below. Everything works perfectly, what we need to change is the szPage from a http link into an https link. As you can see below (commented code) – we have done some testing but with no luck.
Please bid only if you are capable to rewrite/update the function below to work with HTTPS and with CURL library Version 7.28.0. If the library is the problem and needs to be updated – I need your support for implementing that change in the Visual Studio 2008 project.
BOOL SendRequestToServerCurl(CServerInfo& ServerInfo, const CString& szReport, const CString& szPage, CString& szResponse)
{
try{
SINFO_FNC();
curl_version_info_data *data;
data = curl_version_info(CURLVERSION_NOW);
CURL* http_handle_t;
CURLcode result_t;
long response_code_t;
//new
curl_global_init(CURL_GLOBAL_ALL);
wprintf(_T("curl_easy_init.... \n\n"));
http_handle_t = curl_easy_init();
struct MemoryStruct mem;
char *sValue = 0;
CString wcsValue;
DWORD dwToWrite;
mem.memory = (char *)malloc(1);
mem.size = 0;
(szPage.Find(_T("#")) == -1) ? ServerInfo.SetPage(szPage) : ServerInfo.SetPage(ServerInfo.GetPath( ) + szPage.Right(szPage.GetLength( ) - 1));
wcsValue = ServerInfo.GetPathSlashPage( );
dwToWrite = WideCharToMultiByte(CP_UTF8, 0, (LPWSTR)wcsValue.GetString( ), -1, NULL, 0, NULL, NULL);
sValue = new char[dwToWrite + 1];
sValue[dwToWrite] = '\0';
WideCharToMultiByte(CP_UTF8, 0, (LPWSTR)wcsValue.GetString( ), -1, sValue, dwToWrite, NULL, NULL);
wprintf(_T("curl_easy_setopt CURLOPT_URL .... \n\n %s \n\n"), CString(sValue));
curl_easy_setopt(http_handle_t, CURLOPT_URL, sValue);
dwToWrite = WideCharToMultiByte(CP_UTF8, 0, (LPWSTR)szReport.GetString( ), -1, NULL, 0, NULL, NULL);
sValue = new char[dwToWrite + 1];
sValue[dwToWrite] = '\0';
WideCharToMultiByte(CP_UTF8, 0, (LPWSTR)szReport.GetString( ), -1, sValue, dwToWrite, NULL, NULL);
wprintf(_T("curl_easy_setopt.... \n\n"));
curl_easy_setopt(http_handle_t, CURLOPT_POST);
wprintf(_T("curl_easy_setopt CURLOPT_POSTFIELDS .... \n\n %s \n\n"), CString(sValue));
curl_easy_setopt(http_handle_t, CURLOPT_POSTFIELDS, sValue);
curl_easy_setopt(http_handle_t, CURLOPT_POSTFIELDSIZE, dwToWrite + 1 );
curl_easy_setopt(http_handle_t, CURLOPT_NOPROGRESS, 1);
// catching problem
curl_easy_setopt(http_handle_t, CURLOPT_FRESH_CONNECT, 1);
//new
//curl_easy_setopt(http_handle_t, CURLOPT_SSL_VERIFYPEER, 0L);
//curl_easy_setopt(http_handle_t, CURLOPT_SSL_VERIFYHOST, 0L);
//curl_easy_setopt(http_handle_t, CURLOPT_FORBID_REUSE , 1);
//micutzu - wait max 10 sec to connect
//curl_easy_setopt(http_handle_t, CURLOPT_CONNECTTIMEOUT, 10L);
// timeout 20 sec
//curl_easy_setopt(http_handle_t, CURLOPT_TIMEOUT, 20L);
curl_easy_setopt(http_handle_t, CURLOPT_WRITEFUNCTION, write_callback_func);
curl_easy_setopt(http_handle_t, CURLOPT_WRITEDATA, (void *)&mem);
wprintf(_T("curl_easy_perform.... \n\n"));
result_t = curl_easy_perform(http_handle_t);
wprintf(_T("curl_easy_getinfo.... \n\n"));
curl_easy_getinfo(http_handle_t, CURLINFO_RESPONSE_CODE, &response_code_t);
if ((mem.size)||(response_code_t != 200))
{
if(mem.size)
{
SWARN(_T("received response from server"));
wprintf(_T("received response from server\n mem.memory.... \n\n %s \n\n"), CString(mem.memory));
szResponse = CString(mem.memory);
}
else
{
SWARN(_T("received connection error"));
wprintf(_T("received connection error\n result_t.... \n\n %s \n\n"), CString(curl_easy_strerror(result_t)));
}
}
delete[] sValue;
free(mem.memory);
curl_easy_cleanup(http_handle_t);
return(CURLE_OK == result_t);
}
catch(...)
{
return 0;
}
}
I am looking for a C++ expert who it is able to complete a task: add HTTPs support for an existing C++ project.
The current project uses CURL library Version 7.28.0 (10 Oct 2012) linked statically to a Visual Studio 2008 project.
The current project sends data to the server using HTTP and the function that does that is listed below. Everything works perfectly, what we need to change is the szPage from a http link into an https link. As you can see below (commented code) – we have done some testing but with no luck.
Please bid only if you are capable to rewrite/update the function below to work with HTTPS and with CURL library Version 7.28.0. If the library is the problem and needs to be updated – I need your support for implementing that change in the Visual Studio 2008 project.
BOOL SendRequestToServerCurl(CServerInfo& ServerInfo, const CString& szReport, const CString& szPage, CString& szResponse)
{
try{
SINFO_FNC();
curl_version_info_data *data;
data = curl_version_info(CURLVERSION_NOW);
CURL* http_handle_t;
CURLcode result_t;
long response_code_t;
//new
curl_global_init(CURL_GLOBAL_ALL);
wprintf(_T("curl_easy_init.... \n\n"));
http_handle_t = curl_easy_init();
struct MemoryStruct mem;
char *sValue = 0;
CString wcsValue;
DWORD dwToWrite;
mem.memory = (char *)malloc(1);
mem.size = 0;
(szPage.Find(_T("#")) == -1) ? ServerInfo.SetPage(szPage) : ServerInfo.SetPage(ServerInfo.GetPath( ) + szPage.Right(szPage.GetLength( ) - 1));
wcsValue = ServerInfo.GetPathSlashPage( );
dwToWrite = WideCharToMultiByte(CP_UTF8, 0, (LPWSTR)wcsValue.GetString( ), -1, NULL, 0, NULL, NULL);
sValue = new char[dwToWrite + 1];
sValue[dwToWrite] = '\0';
WideCharToMultiByte(CP_UTF8, 0, (LPWSTR)wcsValue.GetString( ), -1, sValue, dwToWrite, NULL, NULL);
wprintf(_T("curl_easy_setopt CURLOPT_URL .... \n\n %s \n\n"), CString(sValue));
curl_easy_setopt(http_handle_t, CURLOPT_URL, sValue);
dwToWrite = WideCharToMultiByte(CP_UTF8, 0, (LPWSTR)szReport.GetString( ), -1, NULL, 0, NULL, NULL);
sValue = new char[dwToWrite + 1];
sValue[dwToWrite] = '\0';
WideCharToMultiByte(CP_UTF8, 0, (LPWSTR)szReport.GetString( ), -1, sValue, dwToWrite, NULL, NULL);
wprintf(_T("curl_easy_setopt.... \n\n"));
curl_easy_setopt(http_handle_t, CURLOPT_POST);
wprintf(_T("curl_easy_setopt CURLOPT_POSTFIELDS .... \n\n %s \n\n"), CString(sValue));
curl_easy_setopt(http_handle_t, CURLOPT_POSTFIELDS, sValue);
curl_easy_setopt(http_handle_t, CURLOPT_POSTFIELDSIZE, dwToWrite + 1 );
curl_easy_setopt(http_handle_t, CURLOPT_NOPROGRESS, 1);
// catching problem
curl_easy_setopt(http_handle_t, CURLOPT_FRESH_CONNECT, 1);
//new
//curl_easy_setopt(http_handle_t, CURLOPT_SSL_VERIFYPEER, 0L);
//curl_easy_setopt(http_handle_t, CURLOPT_SSL_VERIFYHOST, 0L);
//curl_easy_setopt(http_handle_t, CURLOPT_FORBID_REUSE , 1);
//micutzu - wait max 10 sec to connect
//curl_easy_setopt(http_handle_t, CURLOPT_CONNECTTIMEOUT, 10L);
// timeout 20 sec
//curl_easy_setopt(http_handle_t, CURLOPT_TIMEOUT, 20L);
curl_easy_setopt(http_handle_t, CURLOPT_WRITEFUNCTION, write_callback_func);
curl_easy_setopt(http_handle_t, CURLOPT_WRITEDATA, (void *)&mem);
wprintf(_T("curl_easy_perform.... \n\n"));
result_t = curl_easy_perform(http_handle_t);
wprintf(_T("curl_easy_getinfo.... \n\n"));
curl_easy_getinfo(http_handle_t, CURLINFO_RESPONSE_CODE, &response_code_t);
if ((mem.size)||(response_code_t != 200))
{
if(mem.size)
{
SWARN(_T("received response from server"));
wprintf(_T("received response from server\n mem.memory.... \n\n %s \n\n"), CString(mem.memory));
szResponse = CString(mem.memory);
}
else
{
SWARN(_T("received connection error"));
wprintf(_T("received connection error\n result_t.... \n\n %s \n\n"), CString(curl_easy_strerror(result_t)));
}
}
delete[] sValue;
free(mem.memory);
curl_easy_cleanup(http_handle_t);
return(CURLE_OK == result_t);
}
catch(...)
{
return 0;
}
}