Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
BojanKogoj
Posts: 76
Registered: ‎01-08-2013
My Device: Z10 LE
Accepted Solution

QNetworkAccessManager and problem with header

I'm having some issues with authentication.

According to imgur documentation you only need to use the following for anonymous usage:

 

Authorization: Client-ID YOUR_CLIENT_ID

 Which worked well when I was in QML, I simply used the following with XMLHttpRequest

xmlhttp.setRequestHeader("Authorization", "Client-ID myclientid...");

 Now I'm trying to upload image inside c++, and am getting authentication error. I tried several things including

QNetworkAccessManager* netManager = new QNetworkAccessManager();
QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
...
QHttpPart authPart;
authPart.setRawHeader("Authorization","Client-ID myclientid..");
...
multiPart->append(authPart);
...
QNetworkReply* ipReply = netManager->post(req, multiPart);

 And I'm not quite sure what I'm doing wrong, but it just won't stop returning this

{"data":{"error":"Authentication required","request":"\/3\/upload","method":"POST"},"success":false,"status":401}

 

Please use plain text.
Developer
simon_hain
Posts: 16,137
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: QNetworkAccessManager and problem with header

i would suggest to set the raw header on the request
https://developer.blackberry.com/native/reference/cascades/qnetworkrequest.html#setRawHeader
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
MagnumOpus
Posts: 139
Registered: ‎01-03-2013
My Device: n/a

Re: QNetworkAccessManager and problem with header

On the c++ side listen to the QNetworkAccessManager's authenticationRequired signal and fill in the QAuthenticator that is sent.

Regards.

If my answer has been useful to you, please, click the button
Please use plain text.
Developer
Benecore
Posts: 540
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....

Re: QNetworkAccessManager and problem with header

Just use setRawHeader as suggested simon_hain .

This is what i use for my QtC++ Imgur library

QNetworkRequest request;
request.setRawHeader("Authorization",  "Client-ID YOU_CLIENT_ID");

 



If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
Please use plain text.
Developer
BojanKogoj
Posts: 76
Registered: ‎01-08-2013
My Device: Z10 LE

Re: QNetworkAccessManager and problem with header

Thanks, that solved the problem. You guys are awesome

Please use plain text.