View Full Version : Example for Http put
gaba88
30th November 2010, 05:26
Hello All
This is my first post here and indeed this is a very informative forum. :-)
Can any body provide me an example of doing http put using QNetworkAccessManger class.
I tried a lot but was not successful.
Regards,
tbscope
30th November 2010, 05:47
Please post the errors you get and the code you tried.
gaba88
30th November 2010, 05:57
hello tbscope
thanks for the reply.
I am not getting any errors but the at the same time my data is also not going to the server following is the code i tried:
QNetworkRequest request(QUrl("my url"));
QByteArray data;
QUrl param;
param.addEncodedQueryItem("user_credentials",singleaccesstoken.toAscii());
param.addEncodedQueryItem("login","username");
param.addEncodedQueryItem("password","pwd");
data.append(param.toString().toAscii());
data.remove(0,1);
nam->put(request,data);
where nam is QNetworkAccessManager.
I guess the way i am doing is wrong as this is my first time i am working with put with http.
Please let me know where i need to make changes.
Regards,
tbscope
30th November 2010, 06:17
Your use of a QUrl and addEncodedQueryItem and converting the results to a string certainly seem weird to me.
And are you sure the server accepts a PUT request?
Can you debug the exact data you send to see if it is really what you want to send?
gaba88
30th November 2010, 06:21
hello tbscope
Thats what i want to know, in what manner i should send data when using http put, can you make me clear with that first.
Secondly yes the server accepts data using http put. I just tried to do what i used during http post, so it will great if you can make me understand with the format i need to send the data to the server.
Regards,
tbscope
30th November 2010, 06:28
Add these lines to your code, then look if it is exactly the same as you tried before (when it worked).
#include <QDebug>
qDebug() << param.toString().toAscii();
gaba88
30th November 2010, 06:44
Add these lines to your code, then look if it is exactly the same as you tried before (when it worked).
Hello
I guess there is a misunderstanding i never said that it worked for me earlier, the post methods for a different API call in the server works for me but now i have to send a put request to the server with parameters and i am unable to do that . :-(
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.