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. CURL Request -> HTTP Post equivalent (solved)
Forum Updated to NodeBB v4.3 + New Features

CURL Request -> HTTP Post equivalent (solved)

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 6.7k 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.
  • H Offline
    H Offline
    hypnomaki
    wrote on 30 Dec 2014, 21:28 last edited by
    #1

    Hi,
    I want to connect my QT-Project to a API.
    the API CURL call is :
    "curl -X POST -u username:password https://my.fastbill.com/api/1.0/api.php"

    I Only want to use QT-Libs thats why i tried it with following Code
    @
    QNetworkAccessManager* manager = new QNetworkAccessManager(this);
    QNetworkRequest request;
    QByteArray postData="";
    QUrl Adresse("https://my.fastbill.com/api/1.0/api.php");
    request.setUrl(Adresse);
    network_reply = manager->post(request,postData);
    @

    I can connect to the server this way but the reply alsways is "wrong userdata".
    So i tried various ways to fix this for example:
    @
    Adresse.setUserName("username");
    Adresse.setPassword("password");
    Adresse.setQuery("username:password");
    Adresse.setUserInfo("username:password");
    @

    But not a single one of them works.
    Can you tell me what I'm doing wrong or how to make this Call with the Help of QT-Libs?

    1 Reply Last reply
    1
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 30 Dec 2014, 22:54 last edited by
      #2

      Hi and welcome to devnet,

      Unless I misunderstood, you might be interested by "this":http://doc.qt.io/qt-5/qnetworkaccessmanager.html#authenticationRequired

      Hope it helps

      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
      0
      • C Offline
        C Offline
        ChrisW67
        wrote on 31 Dec 2014, 03:35 last edited by
        #3

        Fastbill expects the Content-Type to be set to application/xml And the POST body to be an XML request. You are not sending a valid XML request, hence the error message about the body. (It also accepts a Json formatted request)

        http://www.fastbill.com/api/en/fundamentals.html#authentification

        1 Reply Last reply
        0
        • H Offline
          H Offline
          hypnomaki
          wrote on 31 Dec 2014, 10:34 last edited by
          #4

          @ChrisW67,
          Thats not the problem. If I send the equal Curl command via my Linux Terminal as told in the api ->
          "curl -X POST -u username:apikey https://my.fastbill.com/api/1.0/api.php"
          the response is that there’s actually no Content. But the login worked!
          And exactly this result is what I want to accomplish with QT-Libs.

          @SGaist, thx I will have a look at it!

          1 Reply Last reply
          0
          • H Offline
            H Offline
            hypnomaki
            wrote on 31 Dec 2014, 10:45 last edited by
            #5

            ALL,

            I now solved the problem....
            Its about the Signal written in the documentation - ChrisW67 sent us the link to.

            There are 2 Possibility’s:

            1. Do it via the Signal

            2. Set a Header to the QNetworkRequest:
              @QString concatenated = username + ":" + password;
              QByteArray data = concatenated.toLocal8Bit().toBase64();
              QString headerData = "Basic " + data;
              request.setRawHeader("Authorization", headerData.toLocal8Bit());@

            Thx again and a happy new year!

            1 Reply Last reply
            1

            1/5

            30 Dec 2014, 21:28

            • Login

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