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

如何在C++\wxWidgets 如何下载C++中的WXWIDGET文件?,c++,download,wxwidgets,C++,Download,Wxwidgets,一直在谷歌上搜索,什么都没有出现!谢谢你的帮助 您没有定义“下载文件”对您意味着什么 如果您想使用HTTP检索某些内容,应该使用类似的客户端库,并发出相应的HTTPGET请求。为此使用类 wxHTTP示例代码: #include <wx/sstream.h> #include <wx/protocol/http.h> wxHTTP get; get.SetHeader(_T("Content-type"), _T("text/html; charset=utf-8"))

一直在谷歌上搜索,什么都没有出现!谢谢你的帮助

您没有定义“下载文件”对您意味着什么

如果您想使用HTTP检索某些内容,应该使用类似的客户端库,并发出相应的HTTP
GET
请求。

为此使用类

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();
#包括
#包括
wxHTTP-get;
get.SetHeader(_T(“内容类型”),_T(“text/html;charset=utf-8”);
get.SetTimeout(10);//10秒的超时时间,而不是10分钟。。。
而(!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;
WXStringoutStream out_stream(&res);
httpStream->读取(输出流);
wxMessageBox(res);
}
其他的
{
wxMessageBox(_T(“无法连接”);
}
wxdelite(httpStream);
get.Close();

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

取决于您想从何处下载它,以及文件服务器如何允许下载文件。服务器可能使用FTP、HTTP或其他更模糊的方式。你的问题中没有有用的信息,无法从中辨别


一般来说,我不会使用wxWidgets来完成这个任务。wxWidgets是一种GUI软件,它为各种事情提供了一些额外的功能,这些功能可能对您的情况有帮助,也可能对您的情况没有帮助。

来自
HTTP
,正如安德烈建议的那样,来自
FTP
使用
wxFTP

wxFTP ftp;

// if you don't use these lines anonymous login will be used
ftp.SetUser("user");
ftp.SetPassword("password");

if ( !ftp.Connect("ftp.wxwindows.org") )
{
    wxLogError("Couldn't connect");
    return;
}

ftp.ChDir("/pub");
wxInputStream *in = ftp.GetInputStream("wxWidgets-4.2.0.tar.gz");
if ( !in )
{
    wxLogError("Coudln't get file");
}
else
{
    size_t size = in->GetSize();
    char *data = new char[size];
    if ( !in->Read(data, size) )
    {
        wxLogError("Read error");
    }
    else
    {
        // file data is in the buffer
        ...
    }

    delete [] data;
    delete in;
}

从哪个位置下载?FTP/HTTP?