2

I'm writing a program that needs to be able to read in HTML source code into a string.

I've read about WebClient for C# but I need to write my program in C++ and I'm not sure how to do that (I've never used WebClient before).

Can anyone give me a simple C++ example program showing me how to get HTML source code into a string using WebClient? (or any better method)

Thanks.

kyrylomyr
  • 12,192
  • 8
  • 52
  • 79
user2054823
  • 23
  • 1
  • 1
  • 4

2 Answers2

2

See this page, A Fully Featured Windows HTTP Wrapper in C++:

http://www.codeproject.com/Articles/66625/A-Fully-Featured-Windows-HTTP-Wrapper-in-C

Sample code from that page, looks like what you want:

void ProgressTest(void)
{
    // Set URL and call back function.
    WinHttpClient client(L"http://www.codeproject.com/", ProgressProc);
    client.SendHttpRequest();
    wstring httpResponseHeader = client.GetResponseHeader();
    wstring httpResponseContent = client.GetResponseContent();
}
Chen
  • 1,654
  • 2
  • 13
  • 21
-2

I don't know what webclient for c# is. To read a file into a string-:

 std::ifstream ifs("webpage.html");
 std::string str;
 str.assign((std::istreambuf_iterator<char>(ifs)),
            (std::istreambuf_iterator<char>()));
suspectus
  • 16,548
  • 8
  • 49
  • 57