如何用libcurl解析HTTP头? [英] How does one parse HTTP headers with libcurl?

查看:1096
本文介绍了如何用libcurl解析HTTP头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在环顾四周,我很惊讶似乎没有办法在libcurl中解析标题(这些日子似乎是http的规范C库)。

I've been looking around and am quite surprised that there seems to be no means by which one can parse headers generically in libcurl (which seems to be the canonical C library for http these days).

我发现最接近的是邮件列表帖子,有人建议其他人搜索邮件列表档案。

The closest thing I've found was a mailing list post where someone suggested someone else search through the mailing list archives.

唯一libcurl通过 setopt 提供的工具是 CURLOPT_HEADERFUNCTION 这将一次为一行提供标题响应。

The only facility that is provided by libcurl via setopt is CURLOPT_HEADERFUNCTION which will feed the header responses a single line at a time.

考虑到标题可以跨越多行。理想情况下,这应该一次正确完成(最好由库本身完成),而不是留给应用程序开发人员不断重新发明。

This seems entirely too primitive considering headers can span multiple lines. Ideally this should be done once correctly (preferably by the library itself) and not left for the application developers to do continually reinvent.

编辑

天真无效的一个例子,请参阅以下要点,其中包含一个libcurl代码示例和一个无法解析的正确形成的http响应: https://gist.github.com/762954

An example of the naïve thing not working, see the following gist with a libcurl code example and a properly formed http response that it can't parse: https://gist.github.com/762954

推荐答案

已经超过一年,所以我想我会把它关闭为手动。或者:

Been over a year, so I think I'll close this as "manually." Or:


如果您遇到cURL问题,我觉得你儿子不好,

If you're having cURL problems, I feel bad for you son,

你有多行标题,必须解析每一个。

You've got multi-line headers and must parse each one.

这篇关于如何用libcurl解析HTTP头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆