Qt之protocol "" is unknown QNetworkReply - 小众知识

Qt之protocol "" is unknown QNetworkReply

2013年01月27日 14:18:05 苏内容

I have the following piece of code.
Qt Code:

  1. QNetworkAccessManager *man = new QNetworkAccessManager(this);
  3. QNetworkRequest getRequest;
  4. getRequest.setUrl((QUrl)requestUrl);
  6. m_svcReply = man->get(getRequest);
  7. connect(m_svcReply, SIGNAL(finished()),this, SLOT(getWebRequestFinished()));
  8. connect(m_svcReply, SIGNAL(error(QNetworkReply::NetworkError)),this, SLOT(webrequestFailed(QNetworkReply::NetworkError)));
To copy to clipboard, switch view to plain text mode 
If I'm executing this request over WIFI, I get a proper response from the server. However if I'm executing this request over 3G, I get a protocol "" is unknown error. Any ideas why this might be happening? Thanks

QUrl downloadUrl = QUrl::fromEncoded(downloadUrlStr.toAscii());

qDebug() << downloadUrl.toString();

QNetworkRequest req(downloadUrl);
req.setAttribute(QNetworkRequest::User, id);
QNetworkReply *finalReply = nam->get(req);
connect(finalReply, SIGNAL(finished()),
this, SLOT(dataFetchFinished()));

I have the above code in my Qt 4.8.4 application, but in the dataFetchFinished() slot I keep detecting the error: Protocol "" is unknown

The debug output is: ""

Any help is much appreciated!


FWIW The QString downloadUrlStr is http%3A%2F%2F192.168.1.1%2Fservlet%2Fcom.roving.report.view.excel.ExcelReportSe‌ ​ rvlet%3Ffile%3D661%26columns%3D0%26srcType%3DdefineBean%26width%3D0%26height%3D0%‌ ​ 26reportParamsId%3D100583%26cachedId%3D662%26t_i_m_e%3D1376086878417&pageStyle=0 –  Turner Aug 9 '13 at 22:46
QUrl::fromPercentEncoding should work. Check out Qt Docs or Sources to see difference between these two. –  elmigranto Aug 9 '13 at 23:48
@elmigranto It works like charm! But I'm still trying to figure out the underlying difference between these two static methods –  Turner Aug 10 '13 at 16:45
Well, fromEncoded is basically QUrl(QString::fromUtf8(QByteArray)); while fromPercentEncoding actually decodes percent encoding. –  elmigranto Aug 12 '13 at 6:43
© CopyRight 2010-2021, PREDREAM.ORG, Inc.All Rights Reserved. 京ICP备13045924号-1