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

How to extract the Location: HTTP header field with libcurl?

本文关键字:HTTP 字段 Location 何使用 libcurl 提取      更新时间:2023-10-16

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

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

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

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

如果您需要经过处理的绝对URL,那么在重定向时,请使用CURLINFO_redirect_URL选项。另请参阅getredirect示例。

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