在带有 MingW 的 Windows 8.1(64 位)上使用 Qt 5.4 32 位。
我遇到了一个奇怪的问题。考虑一下:
//QString m_sUrl = "cloud.mysystem.info/";
//QString m_sFileName = "results.html";
//QNetworkAccessManager m_Manager;
QUrl url(m_sURL + m_sFileName);
url.setScheme("ftp");
url.setUserName(m_sLogin);
url.setPassword(m_sPassword);
QFile *file = new QFile(m_sFileName);
if(file->open(QIODevice::ReadOnly))
{
QNetworkReply *reply = m_Manager.put(QNetworkRequest(url), file);
connect(reply, static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error), this, &OCMResults::error);
connect(reply, &QNetworkReply::finished, reply, &QObject::deleteLater);
connect(reply, &QNetworkReply::finished, file, &QObject::deleteLater);
}
else
file->deleteLater();
起初我的代码运行良好,但后来它停止工作(可能是由于我的更改,不确定它是什么),唯一的解决方法是当我明确地编写 url 时:
QNetworkReply(QUrl("ftp://" + m_sLogin + ":" + m_sPassword + "@" + m_sURL + m_sFileName)), file);
生成的 URL 完全相同,但由于某种原因,当我事先创建它并将其传递给 QNetworkReply 时,它不接受它:
reply.url().host()
例如,如果是这种情况,则不会产生任何结果。我觉得我在这里遗漏了一些非常明显的东西......
错误是:
3 (host not found) when ftp is specified in the url string
301 (unknown protocol) when I do not specify it in the url but specify it as setScheme("ftp") instead
谢谢!