首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >libcurl不适用于http重定向

libcurl不适用于http重定向
EN

Stack Overflow用户
提问于 2014-05-10 01:26:11
回答 1查看 1.3K关注 0票数 2

我开发了一个使用libcurl作为http客户端的应用程序。

我尝试连接到HTTP服务器,服务器返回http重定向到另一个地址,但libcurl在收到http重定向后什么也不做。

我错过了什么?

我的代码:

代码语言:javascript
复制
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);

在流量日志之后:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2014-05-10 01:28:28

您还需要设置CURLOPT_FOLLOWLOCATION标志来告诉curl自动跟随重定向:

代码语言:javascript
复制
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23570634

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档