Results 1 to 2 of 2

Thread: curl into QNetworkAccessManager - help required

  1. #1
    Join Date
    Sep 2008
    Location
    Poland
    Posts
    80
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows
    Thanks
    4
    Thanked 5 Times in 4 Posts

    Default curl into QNetworkAccessManager - help required

    Hey mates

    I have an curl command which works fine:
    curl -X "POST" "http://testapi.box.io/public/v1/partner/authenticate.json" -H "Accept: application/json" -H "Content-Trlencoded" -H "X-API-Authentication: DEV_TEST_TOKEN_STAGING" --data-urlencode "email=DEV_TEST_STAGING@mail.com" --data-urlencode "password=DEV_TEST_STAGING"

    wireshark frame for it:
    Qt Code:
    1. Frame 18: 373 bytes on wire (2984 bits), 373 bytes captured (2984 bits) on interface 0
    2. Linux cooked capture
    3. Packet type: Sent by us (4)
    4. Link-layer address type: 1
    5. Link-layer address length: 6
    6. Source: 70:4d:7b:8a:a6:e0 (70:4d:7b:8a:a6:e0)
    7. Protocol: IPv4 (0x0800)
    8. Internet Protocol Version 4, Src: 192.168.150.254, Dst: 88.198.136.196
    9. Transmission Control Protocol, Src Port: 36584 (36584), Dst Port: 80 (80), Seq: 1, Ack: 1, Len: 305
    10. Source Port: 36584
    11. Destination Port: 80
    12. [Stream index: 0]
    13. [TCP Segment Len: 305]
    14. Sequence number: 1 (relative sequence number)
    15. [Next sequence number: 306 (relative sequence number)]
    16. Acknowledgment number: 1 (relative ack number)
    17. Header Length: 32 bytes
    18. Flags: 0x018 (PSH, ACK)
    19. Window size value: 229
    20. [Calculated window size: 29312]
    21. [Window size scaling factor: 128]
    22. Checksum: 0x3a89 [validation disabled]
    23. Urgent pointer: 0
    24. Options: (12 bytes), No-Operation (NOP), No-Operation (NOP), Timestamps
    25. [SEQ/ACK analysis]
    26. Hypertext Transfer Protocol
    27. POST /public/v1/partner/authenticate.json HTTP/1.1\r\n
    28. [Expert Info (Chat/Sequence): POST /public/v1/partner/authenticate.json HTTP/1.1\r\n]
    29. Request Method: POST
    30. Request URI: /public/v1/partner/authenticate.json
    31. Request Version: HTTP/1.1
    32. Host: api.sandbox.mfb.io\r\n
    33. User-Agent: curl/7.47.0\r\n
    34. Accept: application/json\r\n
    35. Content-Type: application/x-www-form-urlencoded\r\n
    36. X-API-Authentication: DEV_TEST_TOKEN_STAGING\r\n
    37. Content-Length: 59\r\n
    38. \r\n
    39. [Full request URI: http://testapi.box.io/public/v1/partner/authenticate.json]
    40. [HTTP request 1/1]
    41. [Response in frame: 20]
    42. HTML Form URL Encoded: application/x-www-form-urlencoded
    43. Form item: "email" = "DEV_TEST_STAGING@mail.com"
    44. Form item: "password" = "DEV_TEST_STAGING"
    To copy to clipboard, switch view to plain text mode 

    I need to connect to that server via Qt code.So far I've created such:
    Qt Code:
    1. void APIHandler::authentication(const QString &email, const QString &password)
    2. {
    3. QNetworkRequest authRequest(flixAddress);
    4.  
    5. authRequest.setRawHeader("Accept", "application/json");
    6. authRequest.setRawHeader("Content-Type", "application/x-www-form-urlencoded");
    7. authRequest.setRawHeader("Accept‐Language", "en");
    8. authRequest.setRawHeader("X‐Api‐Authentication", flixAPIKey.toLocal8Bit());
    9.  
    10. QByteArray data;
    11. data.append("email=" + email + '&');
    12. data.append("password=" + password);
    13.  
    14. QNetworkReply *reply = networkManager->post(authRequest, data);//networkManager is QNetworkAccessManager
    15. reply->setObjectName(FLIX_AUTH_REQUEST);//do późniejszej identyfikacji w slocie networkReply()
    16. }
    To copy to clipboard, switch view to plain text mode 
    but it does not work,and I have no idea why.Well,one difference compared to curl is my code sends two packets,one with header data,and one with email&password.
    What I'm doing wrong?

    thanks for tips and regards,
    MasterBLB

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Qt products
    Qt5
    Platforms
    MacOS X
    Thanks
    13
    Thanked 153 Times in 150 Posts

    Default Re: curl into QNetworkAccessManager - help required

    What is the http status after your post is finished? Also, what is the contents of flixAddress?
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

Similar Threads

  1. Curl in Qt
    By linujoseph23 in forum Newbie
    Replies: 2
    Last Post: 23rd January 2012, 22:05
  2. Curl in QT Creator
    By januszmk in forum Newbie
    Replies: 10
    Last Post: 26th August 2011, 00:14
  3. Problem with curl writefunction
    By januszmk in forum Qt Programming
    Replies: 5
    Last Post: 27th July 2011, 09:17
  4. cURL & QWebKit don't mix
    By Frankenstein Coder in forum Newbie
    Replies: 1
    Last Post: 20th July 2011, 04:03
  5. QNetworkAccessManager or QHttp help required
    By prasad.borkar in forum Newbie
    Replies: 3
    Last Post: 20th April 2011, 08:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.