問(wèn)題描述
在我用 C++ 編寫的應(yīng)用程序中,我需要解析 URL 以獲取協(xié)議、主機(jī)、路徑和查詢.該應(yīng)用程序旨在跨平臺(tái).我很驚訝我在 boost 或 POCO 庫(kù).是不是很明顯我沒在看?關(guān)于適當(dāng)?shù)拈_源庫(kù)的任何建議?或者這是我必須自己做的事情?這不是超級(jí)復(fù)雜,但似乎是一項(xiàng)常見的任務(wù),我很驚訝沒有通用的解決方案.
I need to parse a URL to get the protocol, host, path, and query in an application I am writing in C++. The application is intended to be cross-platform. I'm surprised I can't find anything that does this in the boost or POCO libraries. Is it somewhere obvious I'm not looking? Any suggestions on appropriate open source libs? Or is this something I just have to do my self? It's not super complicated but it seems like such a common task I am surprised there isn't a common solution.
推薦答案
有一個(gè)建議用于 Boost 包含的庫(kù),它允許您輕松解析 HTTP URI.它使用 Boost.Spirit,也是在 Boost 軟件許可下發(fā)布的.該庫(kù)是 cpp-netlib,您可以在 http://cpp-netlib.github.com/找到其文檔 -- 您可以從 http://github.com/下載最新版本cpp-netlib/cpp-netlib/downloads .
There is a library that's proposed for Boost inclusion and allows you to parse HTTP URI's easily. It uses Boost.Spirit and is also released under the Boost Software License. The library is cpp-netlib which you can find the documentation for at http://cpp-netlib.github.com/ -- you can download the latest release from http://github.com/cpp-netlib/cpp-netlib/downloads .
您將要使用的相關(guān)類型是 boost::network::http::uri
并記錄在 這里.
The relevant type you'll want to use is boost::network::http::uri
and is documented here.
這篇關(guān)于在 C++ 跨平臺(tái)中解析 url 的簡(jiǎn)單方法?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!