如何解决使用查询字符串的Libcurl HTTP GET请求
我正在努力通过传递查询字符串的GET请求。每次运行它时,都会收到410响应,我检查链接是否被删除,但仍然可以访问。
我的代码:
CURLUcode rc;
CURLU* url = curl_url();
CURL* handle = curl_easy_init();
CURLcode res;
struct curl_slist* list = NULL;
if (handle) {
rc = curl_url_set(url,CURLUPART_HOST,"www.example.com",0);
rc = curl_url_set(url,CURLUPART_QUERY,"b=sashio",CURLU_APPENDQUERY);
rc = curl_url_set(url,"id=me_ZwNjBQRlZGL0AwR0ZQNjAQR1AQZ3At==",CURLUPART_SCHEME,"http",CURLUPART_PATH,"/en/m.php?",0);
curl_easy_setopt(handle,CURLOPT_CURLU,url);
list = curl_slist_append(list,"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
curl_easy_setopt(handle,CURLOPT_HTTPHEADER,list);
curl_easy_setopt(handle,CURLOPT_HTTPGET,1L);
curl_easy_setopt(handle,CURLOPT_VERBOSE,CURLOPT_ENCODING,"");
}
res = curl_easy_perform(handle);
详细输出:
* Mark bundle as not supporting multiuse
* HTTP 1.0,assume close after body
< HTTP/1.0 410 Gone
< Date: Wed,12 Aug 2020 19:41:23 GMT
< Server: Apache
< X-UA-Compatible: IE=EmulateIE9
< Last-Modified: Wed,12 Aug 2020 19:41:23 GMT
< Cache-Control: private,must-revalidate,max-age=0
< Etag: "1804121564-00010031-BZGZ0AGt5BQt2AGD1ZQZ1AmV"
< Set-Cookie: PHPSESSID=tp3mbkk7148cm989areejhhd90; path=/
< Expires: Thu,19 Nov 1981 08:52:00 GMT
< Pragma: no-cache
< Content-Length: 192
< Connection: close
< Content-Type: text/html
<
* Closing connection 0
解决方法
特别感谢大家@AndreasWenzel。 浏览器正在向服务器发送cookie ,就像AndreasWenzel所说的那样。所以在标题中,我添加了cookie,现在我收到了正确的响应。 祝你有美好的一天!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。