QNetworkAccessManager->get without VPN returns "Connection closed" from the server
-
I have the following two code snips. The first code snip works fine for the environment with and without VPN. The second code snip only works fine for the environment with VPN, but the second code snip in the environment without VPN returns "Connection closed" or QNetworkReply::RemoteHostClosedError from the same server. All the values that are assigned to the parameters are the same.
First code snip:
var http = new XMLHttpRequest() query = "https://......" http.open("get", query) http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded") http.setRequestHeader("X-API-KEY", "xxxxx") http.setRequestHeader("Cache-Control", "no-cache") http.setRequestHeader("Ocp-Apim-Subscription-Key", "xxxxx") http.send();second code snip:
m_netManager = new QNetworkAccessManager(this); QUrl url = "https://......"; QNetworkRequest request = QNetworkRequest(url); QByteArray baKey = QByteArray(m_apiKey.toLatin1()); // fails without VPN even with the config //QSslConfiguration config = QSslConfiguration::defaultConfiguration(); //config.setProtocol(QSsl::TlsV1_0OrLater); //request.setSslConfiguration(config); request.setRawHeader("Ocp-Apim-Subscription-Key", baKey); request.setRawHeader("X-API-KEY", baKey); request.setRawHeader("Cache-Control", "no-cache"); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); m_serialNumberReply = m_netManager->get(request); -
Hi and welcome to devnet,
You should also connect the error related signals, they might offer some more information.
If nothing interesting appears, you might want to use a tool such as Wireshark to check what happens network wise.
-
I have the following two code snips. The first code snip works fine for the environment with and without VPN. The second code snip only works fine for the environment with VPN, but the second code snip in the environment without VPN returns "Connection closed" or QNetworkReply::RemoteHostClosedError from the same server. All the values that are assigned to the parameters are the same.
First code snip:
var http = new XMLHttpRequest() query = "https://......" http.open("get", query) http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded") http.setRequestHeader("X-API-KEY", "xxxxx") http.setRequestHeader("Cache-Control", "no-cache") http.setRequestHeader("Ocp-Apim-Subscription-Key", "xxxxx") http.send();second code snip:
m_netManager = new QNetworkAccessManager(this); QUrl url = "https://......"; QNetworkRequest request = QNetworkRequest(url); QByteArray baKey = QByteArray(m_apiKey.toLatin1()); // fails without VPN even with the config //QSslConfiguration config = QSslConfiguration::defaultConfiguration(); //config.setProtocol(QSsl::TlsV1_0OrLater); //request.setSslConfiguration(config); request.setRawHeader("Ocp-Apim-Subscription-Key", baKey); request.setRawHeader("X-API-KEY", baKey); request.setRawHeader("Cache-Control", "no-cache"); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); m_serialNumberReply = m_netManager->get(request);Presumably the second snippet is running on your dev machine. Where is the first snippet running? What differs in the network path?
BTW, this from snippet 1:
http.setRequestHeader("Ocp-Apim-Subscription-Key", "xxxxx")and this from snippet 2:
QByteArray baKey = QByteArray(m_apiKey.toLatin1()); request.setRawHeader("Ocp-Apim-Subscription-Key", baKey);may not be generating the same thing in the request, especially if
m_apiKeyis a QString with non-ASCII content. -
Presumably the second snippet is running on your dev machine. Where is the first snippet running? What differs in the network path?
BTW, this from snippet 1:
http.setRequestHeader("Ocp-Apim-Subscription-Key", "xxxxx")and this from snippet 2:
QByteArray baKey = QByteArray(m_apiKey.toLatin1()); request.setRawHeader("Ocp-Apim-Subscription-Key", baKey);may not be generating the same thing in the request, especially if
m_apiKeyis a QString with non-ASCII content.@ChrisW67 they both run on the same machine. they both are in the same Qt project, first code snip is in qml file, the second code snip is in cpp file.
Both "Ocp-Apim-Subscription-Key" has the same value, the baKey just want to show the 'conversion'.