Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I download a file with cpp-httplib #923

Closed
Fuwaki opened this issue May 2, 2021 · 1 comment
Closed

How can I download a file with cpp-httplib #923

Fuwaki opened this issue May 2, 2021 · 1 comment

Comments

@Fuwaki
Copy link

Fuwaki commented May 2, 2021

I have tried using cpp-httplib's Get() to download an image , but it failed and the error code was Read . As you can imagine , the image is not text , but it uses string to store it , which makes it not
worked . So how can I use this library to download files ?

@yhirose
Copy link
Owner

yhirose commented May 2, 2021

@geometry2019, hope this helps.

cpp-httplib/test/test.cc

Lines 357 to 378 in 2a70c45

TEST(ChunkedEncodingTest, FromHTTPWatch) {
auto host = "www.httpwatch.com";
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
auto port = 443;
SSLClient cli(host, port);
#else
auto port = 80;
Client cli(host, port);
#endif
cli.set_connection_timeout(2);
auto res =
cli.Get("/httpgallery/chunked/chunkedimage.aspx?0.4153841143030137");
ASSERT_TRUE(res);
std::string out;
detail::read_file("./image.jpg", out);
EXPECT_EQ(200, res->status);
EXPECT_EQ(out, res->body);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants