来自相对路径的绝对URL

kay*_*kay 6 c uri relative-url

我有一个基本URL和该文档中的一些相对URI我希望拥有绝对路径.

例如base = https://example.com/some/path.html?query=string和该文档中的相对URI:

在Java中,您有类URL实现:

URL abs = new URL(new URL(basePath), relPath);
Run Code Online (Sandbox Code Playgroud)

但奇怪的是,我找不到一个简单的C库或功能实现这一点.

有没有图书馆证明这个功能?或者更好的是一些可以使用的小型自包含文件?

Ano*_*sse 5

你可以打赌这已经用 C 语言写了一千次了。以阿帕奇为例。

以下是一些提示:

libSoup,GNOME 使用的 http 库: http: //developer.gnome.org/libsoup/unstable/SoupURI.html#soup-uri-new-with-base

建议使用 Boost 库:http://cpp-netlib.github.com/

由 Google 自己提供(Chrome 的一部分?): http: //code.google.com/p/google-url/

还有另一个: http: //uriparser.sourceforge.net/

W3C: http: //www.w3.org/Library/src/HTParse

libcamel 中的 URL 解析:http://www.google.com/codesearch#KhbZeNk3OGk/camel/camel-url.c

还有一些 URI 解析 API,它们似乎都没有相对 URI:

GLib,我最喜欢的 C 库:http://developer.gnome.org/glib/unstable/glib-URI-Functions.html

libedataserver(来自 Evolution) http://developer.gnome.org/libedataserver/stable/libedataserver-e-url.html

GNet,一个 glib 插件:http://developer.gnome.org/gnet/stable/gnet-uri.html

  • 尽管“已经用 C 语言编写了一千遍”,但很难找到库,不是吗?HTParse 和 uriparser 看起来不错,其他库要么是 C++ 要么(libcamel)有很多依赖项。稍后我会进一步研究它。谢谢! (2认同)