Reputation: 148
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!
Upvotes: 0
Views: 396
Reputation: 647
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.
Upvotes: 1
Reputation: 73617
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.
Upvotes: 0