下载 C++ 中的 URL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1129194/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 18:56:16  来源:igfitidea点击:

Download a URL in C++

c++sockets

提问by User1

I want to be able to download a URL in C++. Something as simple as:

我希望能够在 C++ 中下载 URL。像这样简单的事情:

std::string s;
s=download("http://www.example.com/myfile.html");

Ideally, this would include URLs like:

理想情况下,这将包括以下 URL:

I was using asio in Boost, but it didn't really seem to have the code for handling protocols like ftp and https. Now I discovered QT has more what I need (http://doc.trolltech.com/2.3/network.html).

我在 Boost 中使用 asio,但它似乎并没有处理像 ftp 和 https 这样的协议的代码。现在我发现 QT 有更多我需要的东西(http://doc.trolltech.com/2.3/network.html)。

It's tempting to make the switch to Qt, but it seems a bit heavy and intersects a lot of Boost functionality. Is it worth learning yet another API (Qt) or can Boost do more than I think?

切换到 Qt 很诱人,但它似乎有点沉重,并且与许多 Boost 功能相交。值得学习另一个 API (Qt) 还是 Boost 能做的比我想象的更多?

回答by Dave Gamble

Not a direct answer, but you might like to consider libCURL, which is almost exactly what you describe.

不是直接的答案,但您可能想考虑libCURL,这几乎正是您所描述的。

There are sample applications here, and in particular thisdemonstrates how simple usage can be.

有示例应用程序在这里,特别是证明了简单的使用都可以。

回答by Gerald

I wouldn't go to Qt just for the networking stuff, since it's really not all that spectacular; there are a lot of missing pieces. I'd only switch if you need the GUI stuff, for which it is top notch.

我不会仅仅为了网络方面的东西而去 Qt,因为它真的不是那么壮观;有很多缺失的部分。如果您需要 GUI 的东西,我只会切换,因为它是一流的。

libCURL is pretty simple to use and more robust than the Qt stuff.

libCURL 使用起来非常简单,而且比 Qt 的东西更健壮。

回答by chrish

The Poco Projecthas classes for cross-platform HTTP and FTP (and a lot of other stuff). There is overlap with boost. I recently foundthis, but have not used it.

波科项目具有跨平台的HTTP和FTP(和很多其他的东西)班。与 boost 有重叠。我最近发现了这个,但没有使用它。

回答by Nick Dandoulakis

You can use the URLDownloadToFileor URLOpenBlockingStream, although cURL, libcurlare the proper tools for that kind of jobs.

您可以使用URLDownloadToFileURLOpenBlockingStream,尽管cURL、libcurl是此类作业的合适工具。

回答by Andrew

I got it working without either libcurl nor WinSock: https://stackoverflow.com/a/51959694/1599699

我在没有 libcurl 和 WinSock 的情况下工作:https: //stackoverflow.com/a/51959694/1599699

Special thanks to Nick Dandoulakisfor suggesting URLOpenBlockingStream! I like it.

特别感谢Nick Dandoulakis建议 URLOpenBlockingStream!我喜欢。