如何在C++\wxWidgets中下载文件

Ada*_*dam 0 c++ wxwidgets download

如何用wxWidgets下载C++文件?

谷歌搜索,一切都没有出现!帮助赞赏!

And*_*ovs 6

使用wxHTTP类.

wxHTTP示例代码:

#include <wx/sstream.h>
#include <wx/protocol/http.h>

wxHTTP get;
get.SetHeader(_T("Content-type"), _T("text/html; charset=utf-8"));
get.SetTimeout(10); // 10 seconds of timeout instead of 10 minutes ...

while (!get.Connect(_T("www.google.com")))
    wxSleep(5);

wxApp::IsMainLoopRunning();

wxInputStream *httpStream = get.GetInputStream(_T("/intl/en/about.html"));

if (get.GetError() == wxPROTO_NOERR)
{
    wxString res;
    wxStringOutputStream out_stream(&res);
    httpStream->Read(out_stream);

    wxMessageBox(res);
}
else
{
    wxMessageBox(_T("Unable to connect!"));
}

wxDELETE(httpStream);
get.Close();
Run Code Online (Sandbox Code Playgroud)

如果您想要更灵活的解决方案,请考虑使用libcurl.