且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从libcurl获取URL的片段部分?

更新时间:2023-02-23 10:18:48

cURL根据错误报告( 2 ).另请参见此修补程序.因此,片段标识符"不能作为CURLINFO_EFFECTIVE_URL的一部分使用.

cURL removes the "fragment identifier" from the URL before making a request, as per the bug reports (1, 2). See also this patch. Thus the "fragment identifier" is not available as part of the CURLINFO_EFFECTIVE_URL.

如果片段标识符"作为重定向的一部分返回(例如,Location HTTP标头),而您无法通过其他任何方式获取它,则可以使用调试模式来窥视之间的通信. cURL和服务器,然后自己提取片段标识符".为此,您需要设置CURLOPT_DEBUGFUNCTIONCURLOPT_HEADERFUNCTION.

If the "fragment identifier" is returned as part of a redirect (e.g. the Location HTTP header) and you can't get it any other way, then you may use the debug modes to peek on the communications between the cURL and the servers and extract the "fragment identifier" yourself. To that end you'll need to setup either CURLOPT_DEBUGFUNCTION or CURLOPT_HEADERFUNCTION.

P.S.一点建议:查阅相关信息非常容易.我做的第一件事是学习#foo=bar的正式"名称.为了得到它,我在 URL ***问了Wikipedia,并被带到

P.S. A bit of advise: Googling the relevant information was very easy. First thing I did was to learn the "official" name of the #foo=bar. To get it I visited Wikipedia at URL and was brought to Fragment identifier. After that, Googling with the "curl fragment" netted the relevant parts. If you're looking for something, learn it's proper name.