Hello
I am trying to download config file of the ESXi over HTTPS. I have to use libcurl, becouse the whole project written on c++. My code:
#include <curl/curl.h>static size_t CurlWriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp);int main() {
CURL *curl;
CURLcode res;
CurlMemoryStruct chunk;
chunk.size=0;
chunk.memory=new char[5300];
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl)
{
res=curl_easy_setopt(curl, CURLOPT_URL,"https://192.168.179.131/folder/Deus Ex Machina/Deus Ex Machina.vmx?dcPath=ha-datacenter&dsName=datastore1");
/* we pass our 'chunk' struct to the callback function */
res=curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&chunk);
/* send all data to this function */
res=curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,CurlWriteMemoryCallback);
/* some servers don't like requests that are made without a user-agent field, so we provide one */
res=curl_easy_setopt(curl, CURLOPT_USERAGENT,"libcurl-agent/1.0");
//Set type of the authentication
res=curl_easy_setopt(curl, CURLOPT_HTTPAUTH,CURLAUTH_BASIC);
//Login for authentication
res=curl_easy_setopt(curl, CURLOPT_USERNAME, "root");
//Password for authentication
res=curl_easy_setopt(curl, CURLOPT_PASSWORD, "master");
//Don't verify the certificate
res=curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
//Same thing with host verifying
res=curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
}
static size_t CurlWriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
size_t realsize = size * nmemb;
CurlMemoryStruct *mem = (CurlMemoryStruct *)userp;
mem->memory =(char*) realloc(mem->memory, mem->size+realsize+1);
if (mem->memory == NULL)
{
/* out of memory! */
printf("not enough memory (realloc returned NULL)\n");
exit(EXIT_FAILURE);
}
memcpy(&(mem->memory[mem->size]), contents, realsize);
mem->size += realsize;
mem->memory[mem->size] = 0;
return realsize;
}
When I type this address ( https://192.168.179.131/folder/Deus Ex Machina/Deus Ex Machina.vmx?dcPath=ha-datacenter&dsName=datastore1 ) in browser, file is being downloaded.
My program even don't run trough CurlWriteMemoryCallback() function - breakpoint does not work. The same code with url "https://192.168.179.131" works absolutely fine.
I can't understand what is wrong.
Hi!
Did you try a VM name not containing spaces? VMware hade troubles in escaping chars in urls all the time.
Else try esacping spaces in the http way...
Tos2k
Hi!
Did you try a VM name not containing spaces? VMware hade troubles in escaping chars in urls all the time.
Else try esacping spaces in the http way...
Tos2k
You are absolutely right. I tried https://192.168.179.131/folder/Deus%20Ex%20Machina/Deus%20Ex%20Machina.vmx?dcPath=ha-datacenter&dsNa... and it works.