Reputation: 3316
I am using libcurl to get http pages and I'm stuck with a problem. The page I am trying to get is: http://newsnow.in/news/tunisians-head-to-elect-president-in-runoff-u-t-san-diego
If you open the page you will receive an error stating that the page isn't redirecting properly. When I try to fetch it libcurl simply hangs, no error whatsoever. I also set the timeout which didn't work, I guess since it received the redirect message. Here is my setting:
curl_easy_setopt(curl, CURLOPT_URL, "http://newsnow.in/news/tunisians-head-to-elect-president-in-runoff-u-t-san-diego"); // should be changed later with setLink()
/* example.com is redirected, so we tell libcurl to follow redirection */
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:31.0) Gecko/20100101 Firefox/31.0");
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 20);
/* send all data to this function */
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, filePtr);
And start it with the usual way:
res = curl_easy_perform(curl);
any ideas on what might solve the problem?
Upvotes: 1
Views: 545
Reputation: 3316
For anyone encountering this problem in the future, following @SSC 's comment I added the verbose flag:
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
And found out the page enters an infinite loop of redirects, this was easily solved using the max redirect flag:
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 3L);
Upvotes: 1