MOHAMED
MOHAMED

Reputation: 43518

libcurl does not work with http redirect

I developed an application that use libcurl as a http client.

I tried to conncet to a HTTP server, the server return http redirect to another address, but the libcurl do nothing after receiving the http redirect.

What I m missing?

my code:

curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_USERNAME, userid);
curl_easy_setopt(curl, CURLOPT_PASSWORD, passwd);
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC|CURLAUTH_DIGEST);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header_list);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, HTTP_TIMEOUT);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, HTTP_TIMEOUT);

here after the traffic log:

GET /openacs/ HTTP/1.1

Host: 192.168.1.110:8080

User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:28.0) Gecko/20100101 Firefox/28.0

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3

Accept-Encoding: gzip, deflate

Connection: keep-alive



HTTP/1.1 301 Moved Permanently

Location: http://192.168.1.133:8080/openacs/acs

Date: Thu, 09 Feb 2012 15:33:15 GMT

Server: Apache/2.2.17 (Ubuntu)

Content-Length: 0

Content-Type: text/html; charset=iso-8859-1

Upvotes: 2

Views: 2097

Answers (1)

Adam Rosenfield
Adam Rosenfield

Reputation: 400274

You also need to set the CURLOPT_FOLLOWLOCATION flag to tell curl to automatically follow redirects:

curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

Upvotes: 5

Related Questions