PDA

View Full Version : curl into QNetworkAccessManager - help required



MasterBLB
25th April 2017, 09:03
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:

Frame 18: 373 bytes on wire (2984 bits), 373 bytes captured (2984 bits) on interface 0
Linux cooked capture
Packet type: Sent by us (4)
Link-layer address type: 1
Link-layer address length: 6
Source: 70:4d:7b:8a:a6:e0 (70:4d:7b:8a:a6:e0)
Protocol: IPv4 (0x0800)
Internet Protocol Version 4, Src: 192.168.150.254, Dst: 88.198.136.196
Transmission Control Protocol, Src Port: 36584 (36584), Dst Port: 80 (80), Seq: 1, Ack: 1, Len: 305
Source Port: 36584
Destination Port: 80
[Stream index: 0]
[TCP Segment Len: 305]
Sequence number: 1 (relative sequence number)
[Next sequence number: 306 (relative sequence number)]
Acknowledgment number: 1 (relative ack number)
Header Length: 32 bytes
Flags: 0x018 (PSH, ACK)
Window size value: 229
[Calculated window size: 29312]
[Window size scaling factor: 128]
Checksum: 0x3a89 [validation disabled]
Urgent pointer: 0
Options: (12 bytes), No-Operation (NOP), No-Operation (NOP), Timestamps
[SEQ/ACK analysis]
Hypertext Transfer Protocol
POST /public/v1/partner/authenticate.json HTTP/1.1\r\n
[Expert Info (Chat/Sequence): POST /public/v1/partner/authenticate.json HTTP/1.1\r\n]
Request Method: POST
Request URI: /public/v1/partner/authenticate.json
Request Version: HTTP/1.1
Host: api.sandbox.mfb.io\r\n
User-Agent: curl/7.47.0\r\n
Accept: application/json\r\n
Content-Type: application/x-www-form-urlencoded\r\n
X-API-Authentication: DEV_TEST_TOKEN_STAGING\r\n
Content-Length: 59\r\n
\r\n
[Full request URI: http://testapi.box.io/public/v1/partner/authenticate.json]
[HTTP request 1/1]
[Response in frame: 20]
HTML Form URL Encoded: application/x-www-form-urlencoded
Form item: "email" = "DEV_TEST_STAGING@mail.com"
Form item: "password" = "DEV_TEST_STAGING"

I need to connect to that server via Qt code.So far I've created such:


void APIHandler::authentication(const QString &email, const QString &password)
{
QNetworkRequest authRequest(flixAddress);

authRequest.setRawHeader("Accept", "application/json");
authRequest.setRawHeader("Content-Type", "application/x-www-form-urlencoded");
authRequest.setRawHeader("Accept‐Language", "en");
authRequest.setRawHeader("X‐Api‐Authentication", flixAPIKey.toLocal8Bit());

QByteArray data;
data.append("email=" + email + '&');
data.append("password=" + password);

QNetworkReply *reply = networkManager->post(authRequest, data);//networkManager is QNetworkAccessManager
reply->setObjectName(FLIX_AUTH_REQUEST);//do późniejszej identyfikacji w slocie networkReply()
}
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

jefftee
26th April 2017, 16:49
What is the http status after your post is finished? Also, what is the contents of flixAddress?