cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: socks5, problems with getting page

From: Anton Nagorniy <anton20vlad_at_mail.ru>
Date: Mon, 04 Dec 2006 09:08:44 +0300

-----Original Message-----
From: Anton Nagorniy <anton20vlad_at_mail.ru>
To: curl-library_at_cool.haxx.se
Date: Sun, 03 Dec 2006 19:18:46 +0300
Subject: socks5, problems with getting page

>
> 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.
>
It seems that the problem is in CURLOPT_FOLLOWLOCATION. If it is 1 - page is truncated, if 0 - is not.

But I need this option turned on. How can I manage with this problem?

Thank you.
Received on 2006-12-04