Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何使用libcurl提取Location:HTTP头字段?_C++_C_Curl_Libcurl - Fatal编程技术网

C++ 如何使用libcurl提取Location:HTTP头字段?

C++ 如何使用libcurl提取Location:HTTP头字段?,c++,c,curl,libcurl,C++,C,Curl,Libcurl,我在应用程序中使用libcurl作为http客户机。我可以使用libcurl发送和接收http消息 如上所述,当我收到带有http 302的消息时,我想从收到的http消息中提取location字段 HTTP/1.1 302 Found Location: http://192.168.201.1 Content-Length: 0 当我收到http 302消息时,如何提取位置字段?如果需要处理,在执行重定向时不会登录的绝对URL,请使用选项。另请参见示例 当需要Location头的原始值时,

我在应用程序中使用libcurl作为http客户机。我可以使用libcurl发送和接收http消息

如上所述,当我收到带有http 302的消息时,我想从收到的http消息中提取
location
字段

HTTP/1.1 302 Found
Location: http://192.168.201.1
Content-Length: 0

当我收到http 302消息时,如何提取
位置
字段?

如果需要处理,在执行重定向时不会登录的绝对URL,请使用选项。另请参见示例


当需要
Location
头的原始值时,需要实现回调并等待头到达。

@el.pescado我是否应该使用libcurl进行重定向以获取http url重定向信息?因为我不想。我只想提取信息,就这些。你看过链接页面了吗?“如果启用CURLOPT_FOLLOWLOCATION,接收重定向将带您到的URL”。换句话说,它告诉你,如果你按照它去做,重定向会去哪里。特别是,如果重定向是一个相对URL,它将获取原始URL并计算出绝对目标URL。@el.pescado,它可以工作。谢谢基于这个问题,我还向curl站点添加了一个getredirect示例,展示了如何使用它: