Solved QNetworkReply reply 301 issue
-
Also consider using QNetworkRequest::FollowRedirectsAttribute, if that suits your need :)
Cheers.
-
@jsulm
Did you mean i have to change the website like this ?manager->get(QNetworkRequest(QUrl("https://www.qt.io/developers")));
-
@victor-wang You can, or do what @Paul-Colby suggested.
-
@jsulm
It's not wok.
It still will print 301 out.
@Paul-Colby
I will try it. -
@victor-wang It should work. Did you rebuild?
-
@jsulm
Yes, i had rebuild it.But QNetworkReply::NetworkError still print 301 out to me.
The information said if you receive 301 it means "the Network Access API cannot honor the request because the protocol is not known" .
@Paul-Colby
Why i can't find FollowRedirectsAttribute on my Qt? -
@victor-wang FollowRedirectsAttribute was introduced in Qt 5.6. Which Qt version do you use?
-
@jsulm
Yes, i had rebuild it.But QNetworkReply::NetworkError still print 301 out to me.
The information said if you receive 301 it means "the Network Access API cannot honor the request because the protocol is not known" .
I'm using Qt5.5 that's why i can't using it.
-
@victor-wang Please read the link I provided. 301 means:
"The HTTP response status code 301 Moved Permanently is used for permanent URL redirection" - it is not related to protocol. -
@victor-wang You will need to handle redirections (301) by yourself: the new URL should be in the response (see the link I posted):
HTTP/1.1 301 Moved Permanently Location: http://www.example.org/index.asp
"Location" contains the new URL.
-
@jsulm
I'm using "http://www.example.org/index.asp"
But i get the error 404.
Why is that happened? -
@victor-wang Can you access this URL using a web browser on the same machine?
Did you enter the URL correctly in your code? -
-
@victor-wang Interesting: I can access that URL in a browser but ping does not work.
Maybe there is something with out network? Do you have a proxy? Firewall? -
@jsulm
I had find the solution.
Qt cannot recognize the title "www1.winmate" but recognize the IP address for instead.
I changed it into ip address and it worked! -
@jsulm I think you are misreading the question: this is not about HTTP status 301 (which would indeed be a redirect), but about the QNetworkReply::NetworkError enum, where 301 means "the Network Access API cannot honor the request because the protocol is not known". I'm currently struggling with a similar issue with a particular Qt build where this pops up for HTTPS (HTTP itself is fine, so I'm guessing I didn't do the SSL dependencies right...)