November 3, 2010

syedasadalibs03 syedasadalib..
Lab Rat
24 posts

Qhttp Post method Sample Require !

Page  
1

Hello All
i am new to Qt I have to sent Requet to Web Serve through Qhttp Post method
so any one can share the working sample of Qhttp Post

i want to use for Symbain

Thanks in Advance

24 replies

November 3, 2010

Antonio Di Monaco Antonio Di Monaco
Lab Rat
117 posts

Hi,

just call the post method of QNetworkAccessManager, i.e.

  1. QNetworkReply * post ( const QNetworkRequest & request, const QByteArray & data )

passing:

  • a QNetworkRequest built the URL that you wish to contact, without the query part.
  • a QByteArray filled with your request parameters, i.e. “param1=value1&param2=value2& … “

It works for Desktop, but it should work for Symbian too.

Of course you’ll get a QNetworkReply, but you’ll manage it in the same way as GET method, so you can read some other examples related to QNetworkReply.

Tony.

November 3, 2010

Antonio Di Monaco Antonio Di Monaco
Lab Rat
117 posts

Btw, I noticed that you were talking about QHttp, but I don’t suggest you to use it, cause it has been deprecated by Qt guys.

T.

November 3, 2010

Volker Volker
Ant Farmer
5428 posts

This class is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

You should go with“QNetworkAccessManager”:http://doc.qt.nokia.com/4.7/qnetworkaccessmanager.html and it’s post() [doc.qt.nokia.com] method together with QNetworkRequest [doc.qt.nokia.com]

December 9, 2010

Raul Raul
Lab Rat
120 posts

Why has QHttp been deprecated? that class is really practical

 Signature 

Raul Guerrero
http://jimi.mx

December 9, 2010

Vass Vass
Ant Farmer
743 posts

Raul, no, QNetworkAccessManager look more flexible. Though on first view it seems uncomfortably.

 Signature 


Vasiliy

December 9, 2010

Raul Raul
Lab Rat
120 posts

You’re right, it is more flexible, what I meant by practical is just that, what makes the Qt Framework so cool is not just the functionality, but the fact that the framework feels “natural”.

So the fact that they removed QHttp which made HTTP network access more “natural” or easier to use, they whould have just improved QHttp and keep it easy to use, instead of implementing something new like QNetworkAccessManager and making it harder to use.

I just hope that they don’t make a lot of changes like that, which makes Qt less understandable, and keep it like it is right now, “natural”.

 Signature 

Raul Guerrero
http://jimi.mx

December 9, 2010

Volker Volker
Ant Farmer
5428 posts

Ok, it’s deprecated, but not removed from the libs, so, you still can use it.

December 9, 2010

Raul Raul
Lab Rat
120 posts

Yeah, I can still use it, but being deprecated it’s not really a good practice to continue using it.

I’ll learn about QNetworkAccessManager and hope that things don’t get too complicated for simple tasks ;)

And in the future there are changes in the API that I think could be done better, that’s the great thing about open source and having wikis and forums, people can contribute, give opinions and improvements.

 Signature 

Raul Guerrero
http://jimi.mx

December 9, 2010

Volker Volker
Ant Farmer
5428 posts

Yes, that’s true. And in the end you always can grab the sources and continue to use it yourself.

May I ask, what you’re doing with QHttp, maybe we can give you a hint to the right direction…

December 10, 2010

Raul Raul
Lab Rat
120 posts

A SOAP and REST producer/consumer, for producer I need to build an HTTP Server, and for a client I need to be able to post information to the server.
It’s pretty much a lot of XML/text parsing, and using the HTTP or HTTPS protocol as a transport, for me I felt it was cleaner to use QHttp, because if I want to exchange transports, it sounds more practical to just change QHttp to QFtp to QSomeOtherProtocol, than having to exchange QNetworkAccessManager with QFtp.
As I wrote earlier, it’s for better readability and to make the code more “natural”.

 Signature 

Raul Guerrero
http://jimi.mx

December 10, 2010

QtK QtK
Lab Rat
1140 posts

syedasadalibs03 wrote:
Hello All
i am new to Qt I have to sent Requet to Web Serve through Qhttp Post method
so any one can share the working sample of Qhttp Post

i want to use for Symbain

Thanks in Advance

This [wiki.forum.nokia.com] wiki article may help you.

December 16, 2010

Volker Volker
Ant Farmer
5428 posts
Raul wrote:
…for me I felt it was cleaner to use QHttp, because if I want to exchange transports, it sounds more practical to just change QHttp to QFtp to QSomeOtherProtocol, than having to exchange QNetworkAccessManager with QFtp. As I wrote earlier, it’s for better readability and to make the code more “natural”.

QNetworkAccessManager does support FTP too; you would only have to change the URLs of your request and not even exchange some classes.

December 16, 2010

Raul Raul
Lab Rat
120 posts

Ok cool, and is it easy to implement my own protocols? by just implementing my own protocol class would the QNetworkAccessManager know what class to call depending on what you place on the URL?

 Signature 

Raul Guerrero
http://jimi.mx

December 16, 2010

Volker Volker
Ant Farmer
5428 posts

Implementing your own protocol does need a bit more work (Subclassing QNetworkAccessManager and QNetworkReply). I once did it for your project, and it’s not a kind of rocket science :-) I can give you an example if you want.

December 16, 2010

peppe peppe
Ant Farmer
1029 posts
Raul wrote:
Ok cool, and is it easy to implement my own protocols? by just implementing my own protocol class would the QNetworkAccessManager know what class to call depending on what you place on the URL?

Simply subclass QNetworkAccessManager, override its createRequest1 method, and in there check the protocol inside the URL: if it’s your custom protocol, do whatever you have to do to serve the request and return a custom QNetworkReply subclass. Otherwise simply call the base class implementation.

Remember that QNAM / QNR design is 100% asynchronous, therefore you’re not expected to block in any case.

1 Quite a strange name, since it actually creates a reply!

 Signature 

Software Engineer
KDAB (UK) Ltd., a KDAB Group company

Page  
1

  ‹‹ SQLIte database, How do I improve insert statement speed?      Input Data in Qwebview Web Page ››

You must log in to post a reply. Not a member yet? Register here!