curl-library
socks5, problems with getting page
Date: Sun, 03 Dec 2006 19:18:46 +0300
Hi, I hope I've made everything right, and someone will read this mail :)
I want to load page through the socks5 proxy server. Please tell me what I am doing wrong because the page I get is not full, it is truncated. Here is the code fragment:
void *myrealloc(void *ptr, size_t size)
{
if(ptr!=NULL)
return realloc(ptr, size);
else
return malloc(size);
}
static size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data)
{
size_t realsize = size * nmemb;
struct MemoryStruct *mem = (struct MemoryStruct *)data;
mem->memory = (char *)myrealloc(mem->memory, mem->size + realsize + 1);
if (mem->memory)
{
memcpy(&(mem->memory[mem->size]), ptr, realsize);
mem->size += realsize;
mem->memory[mem->size] = 0;
}
return realsize;
}
void loadUrl()
{
...
chunk.memory=NULL;
chunk.size = 0;
...
curl_easy_setopt(curl, CURLOPT_URL, url);
sendCookies(nc, curl);
curl_easy_setopt(curl, CURLOPT_NOBODY, 0);
curl_easy_setopt(curl, CURLOPT_PROXY, proxy);
curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &WriteMemoryCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0");
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
res = curl_easy_perform(curl);
if(chunk.memory)
{
String content = chunk.memory;
free(chunk.memory);
return content;
}
}
But when I comment
// curl_easy_setopt(curl, CURLOPT_PROXY, proxy);
// curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
everything works fine.
Thank you.
Received on 2006-12-03