4

I use a object of QNetworkAccessManager to post json data to a website.

when handle the reply which is a pointer of QNetworkReply class in the slot function, the value of reply->error() is 301 and the value of reply->errorString() is Error downloading http://www.example.com/query - server replied: Service Unavailable.

I check the documentation of QNetworkReply, the description of this error is:

QNetworkReply::ProtocolUnknownError|301|the Network Access API cannot honor the request because the protocol is not known

and I also known this error is different form the http status 301.

and I have add http:// before the url.

Can someone give some info about this?

ymoreau
  • 3,402
  • 1
  • 22
  • 60
stamaimer
  • 6,227
  • 5
  • 34
  • 55

1 Answers1

0

Since it's a 301 status code there's a redirect. In QtNetwork the ProtocolUnknownError is returned for redirects if the resolved URL is invalid[0] or does not use the http/https scheme[1]

Since I do not know what target-URL you get redirected to I cannot say for sure that this is what the problem is though.

[0] https://github.com/qt/qtbase/blob/5.15/src/network/access/qhttpnetworkconnection.cpp#L546
[1] https://github.com/qt/qtbase/blob/5.15/src/network/access/qhttpnetworkconnection.cpp#L563

Morten242
  • 139
  • 1
  • 13