Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QNetworkAccessManager->get without VPN returns "Connection closed" from the server

QNetworkAccessManager->get without VPN returns "Connection closed" from the server

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 424 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cnm_marketing
    wrote on last edited by
    #1

    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);
    
    C 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • C cnm_marketing

        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);
        
        C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #3

        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_apiKey is a QString with non-ASCII content.

        C 1 Reply Last reply
        0
        • C ChrisW67

          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_apiKey is a QString with non-ASCII content.

          C Offline
          C Offline
          cnm_marketing
          wrote on last edited by
          #4

          @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'.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved