0

first of all I'm aware of the fact that I'm not the first person to ask this, but I do need a different solution than libcurl.

What I want to do basically is make a HTTP request to a server and read the response into an std::string value (char* or CString would be fine as well).

libcurl is too big for my preference (I need to do static linking; I can't ship DLLs with my application and I'd like to keep it as small as possible, curl makes my app about 3M bigger).

Thanks for helping!

2
  • 2
    cURL and its library is tiny compared to many other. It also does just about one thing, and does it well, compared to other HTTP libraries which are part of larger (much larger) frameworks. The cURL library can also be built to a static library without problems, and the nice thing about modern linkers is that they don't pull in library code not used. The only way to get a smaller library would almost be to make one yourself, but then you have to be able to handle all the quirks and corner-cases of the HTTP. Commented Apr 19, 2015 at 10:24
  • Also, you mention CString which indicates you're using the MFC framework, which is way larger than cURL. It also indicates you're targeting Windows, and even on the smallest Windows phone systems a few MB is not very much these days. Commented Apr 19, 2015 at 10:28

2 Answers 2

1

I had exactly the same problem and my solution was:

DeleteUrlCacheEntryA("http://example.com/file.txt");
DWORD state = URLDownloadToFileA(NULL, "http://example.com/file.txt", "file.txt", 0, NULL);
if (state != S_OK)
{
    // can not download...
    return;
}

std::ifstream file("file.txt");
std::string result((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
file.close();
DeleteFileA("file.txt");

It's a little bit inaccurate because of the temporary file, but it works for me and I hope it will be useful for you.

Sign up to request clarification or add additional context in comments.

Comments

0

Taking into consideration that you apparently target windows as platform, you can consider using the windows http services api.

It's not portable to other platforms, but it has the advantage of being built in. MSDN provides lots of explanations and examples on how to use it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.