来自相对路径的绝对 URL [英] Absolute URL from relative path

查看:46
本文介绍了来自相对路径的绝对 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在该文档中有一个基本 URL 和一些相对 URI,我想拥有其绝对路径.

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

在 Java 中,您有 类 URL 实现:

URL abs = new URL(new URL(basePath), relPath);

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

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

解决方案

你可以打赌这已经用 C 编写了一千次了.例如,对于 apache.

这里有一些提示:

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

I've got a base URL and some relative URIs in that document I want to have the absolute path of.

E.g. base = https://example.com/some/path.html?query=string and relative URIs in that document:

In Java you have the class URL accomplishing that:

URL abs = new URL(new URL(basePath), relPath);

But strangely enough I can't find a plain C library or function realizing just that.

Is there a library proving that feature? Or better yet some small self-contained file one can use?

解决方案

You can bet this has been written a thousand times in C already. For apache, for example.

Here are some pointers:

libSoup, the http library used by GNOME: http://developer.gnome.org/libsoup/unstable/SoupURI.html#soup-uri-new-with-base

Proposed for Boost libraries: http://cpp-netlib.github.com/

By Google themselves (part of Chrome?): http://code.google.com/p/google-url/

Yet another: http://uriparser.sourceforge.net/

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

URL parsing in libcamel: http://www.google.com/codesearch#KhbZeNk3OGk/camel/camel-url.c

Some more URI parsing APIs, that all seem to not have relative URIs:

GLib, my favorite C library: http://developer.gnome.org/glib/unstable/glib-URI-Functions.html

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

GNet, a glib addon: http://developer.gnome.org/gnet/stable/gnet-uri.html

这篇关于来自相对路径的绝对 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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