Solved XHR empty responseText
-
hi,
import QtQuick 2.5 import QtQuick.Window 2.2 import QtQuick.Controls 2.2 Window { visible: true width: 640 height: 480 title: qsTr("Hello World") Button{ onClicked: { var doc = new XMLHttpRequest(); doc.onreadystatechange = function() { if (doc.readyState === XMLHttpRequest.HEADERS_RECEIVED) { showRequestInfo("Headers -->"); showRequestInfo(doc.getAllResponseHeaders ()); showRequestInfo("Last modified -->"); showRequestInfo(doc.getResponseHeader ("Last-Modified")); } else if (doc.readyState === XMLHttpRequest.DONE) { console.log("OK : " + doc.responseText) } } doc.open("GET", "www.google.fr"); doc.send(); } } }
why responseText is empty please ?
qt5.11 mingw32 -
@LeLev
what is the value of thestatus
property?
Is OpenSSL available? -
@raven-worx thx,
status is 0 with : doc.open("GET", "www.google.fr");
but i tryed : doc.open("GET", "https://www.google.fr")
now status 200 and i have headers received, but doc.readyState === XMLHttpRequest.DONE is never true.
and i have this errorsqt.network.ssl: QSslSocket: cannot resolve TLSv1_1_client_method qt.network.ssl: QSslSocket: cannot resolve TLSv1_2_client_method qt.network.ssl: QSslSocket: cannot resolve TLSv1_1_server_method qt.network.ssl: QSslSocket: cannot resolve TLSv1_2_server_method qt.network.ssl: QSslSocket: cannot resolve SSL_select_next_proto qt.network.ssl: QSslSocket: cannot resolve SSL_CTX_set_next_proto_select_cb qt.network.ssl: QSslSocket: cannot resolve SSL_get0_next_proto_negotiated qt.network.ssl: QSslSocket: cannot resolve SSL_set_alpn_protos qt.network.ssl: QSslSocket: cannot resolve SSL_CTX_set_alpn_select_cb qt.network.ssl: QSslSocket: cannot resolve SSL_get0_alpn_selected qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated
i installed openssl and pasted the dlls near the executable.
This code was working without openSll (with the same errors..)..
-
Now im running this exemple project : http://doc.qt.io/qt-5/qtqml-xmlhttprequest-example.html
error a this line :
var a = doc.responseXML.documentElement;
qrc:///qml/xmlhttprequest/methods.js:68: TypeError: Cannot read property 'documentElement' of null
2 day im trying to get 1 html page content ...
I also had a working project using : QNetworkAccessManager/QNetworkReply that is not working anymore...
-
@LeLev said in XHR empty responseText:
This code was working without openSll (with the same errors..)..
when was it working? long time ago right?
Google automatically changed to redirecting to https at some time ago.status is 0 with : doc.open("GET", "www.google.fr");
but i tryed : doc.open("GET", "https://www.google.fr")Thats what i was after. Status 0 indicates that it actually tried to access
file://www.google.fr
So your issue is that it can't decrypt SSL connection.
What Qt version are you using?
What OpenSSL version?
Where did you place the OpenSSL libs?
Easiest would be to add the directory path of the dll files to the PATH variable. For deployment right next to the executable then. -
@raven-worx said in XHR empty responseText:
when was it working? long time ago right?
about one year ago ..
i tryed with qt5.6 and 5.8 / 5.11 mingw32
i installed openSSL 32 (and 64) 1.1.0. (putted libeay32.dll and ssleay32.dll near the executable of my app)
@raven-worx said in XHR empty responseText:
Easiest would be to add the directory path of the dll files to the PATH variable. For deployment right next to the executable then.
could you please tell me where you download openSSl . And what 'Path', windows environment variables ? or in Qt ? could you please show an exemple ?
Thx!
-
Hi,
@LeLev said in XHR empty responseText:
i installed openSSL 32 (and 64) 1.1.0.
That's the problem, currently you need to install the latest of the 1.0.X release. The OpenSSL project broke API and ABI compatibility with the 1.1 release. Since Qt 5.10, there's also a backend for OpenSSL 1.1 but you'll have to build Qt yourself to use it.
-
@raven-worx and @SGaist pleae correct me if im wrong but openSSL is not required for xmlhttprequest right ?
@raven-worx said in XHR empty responseText:
Google automatically changed to redirecting to https at some time ago.
I don't have this probleme only with Google but avery website i test .
-
@LeLev said in XHR empty responseText:
I don't have this probleme only with Google but avery website i test .
yes, when you omit the
http://
- i already explained why.
You get the OpenSSL errors only when the website redirects to https. Which doesn't happen on all sites, but on most already. -
@LeLev finnaly i installed Win32OpenSSL-1_0_2, i still have qt.network.ssl: QSslSocket: warnings but its working thank you.