如何使用 libcurl 提取 Location: HTTP header 字段?
How to extract the Location: HTTP header field with 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 消息时,如何提取 location
字段?
如果您需要经过处理的绝对 URL,您将在重定向后到达,请使用 CURLINFO_REDIRECT_URL option. See also the getredirect 示例。
当你需要 Location
header 的原始值时,你需要实现 CURLOPT_HEADERFUNCTION 回调并等待 header 到达。
我在我的应用程序中使用 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 option. See also the getredirect 示例。
当你需要 Location
header 的原始值时,你需要实现 CURLOPT_HEADERFUNCTION 回调并等待 header 到达。