Qhttp Post method Sample Require !



  • 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



  • Hi,

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

    @
    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.



  • 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.



  • bq. 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()":http://doc.qt.nokia.com/4.7/qnetworkaccessmanager.html#post-2 method together with "QNetworkRequest":http://doc.qt.nokia.com/4.7/qnetworkrequest.html



  • Why has QHttp been deprecated? that class is really practical



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



  • 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".



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



  • 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.



  • 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...



  • 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".



  • [quote author="syedasadalibs03" date="1288798157"]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[/quote]

    "This":http://wiki.forum.nokia.com/index.php/CS001431_-_Creating_an_HTTP_network_request_in_Qt wiki article may help you.



  • [quote author="Raul" date="1291943896"]...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".[/quote]

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



  • 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?



  • 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.



  • [quote author="Raul" date="1292457329"]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?[/quote]

    Simply subclass QNetworkAccessManager, override its createRequest[1] 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.

    fn1. Quite a strange name, since it actually creates a reply!



  • [quote author="peppe" date="1292491742"]Remember that QNAM / QNR design is 100% asynchronous, therefore you're not expected to block in any case.[/quote]

    As far as I know, it's not forbidden to do a synchronous (blocking) network access there. The UI is only not responsive in that time. And I know that it definitely works with blocking transfers, as that's what we did in our QNetworkReply subclass (although emitting readyRead signal is tricky :-) ).



  • Surely you can do that, but that's not what your users expect from QNAM.



  • It depends on what you do (as almost always in our business :) ). In most cases you are right, but there are a good bunch of situations where synchronous transfer is critical to the application design, e.g. think of (writing) database access, where you must know if it went good or not. HTTP is more than web sites nowadays ;)



  • [quote author="Volker" date="1291934071"]Ok, it's deprecated, but not removed from the libs, so, you still can use it.[/quote]

    According to Synaptics, I have installed the package libqt4-qt3support. Though, it seems I don't have the QHttp Class, as it is neither found by netbeans, nor by my search funcion or manually.

    My aim is to use http://medieninf.de/qmapcontrol/ for embedding a (offline) map in my qt application (Only for Desktop so far.).
    It's the best libary I have found, but it's outdated (using QHttp...) and I guess there are better libs. So I am hoping for your ideas.

    If QMapControl is really the only package that fits my needs, I will try to replace QHttp by QNetworkAccessManager. But I don't have much experience in programming, so I am afraid of changeing sources.

    Hopeing for your Help!
    Konstantin



  • If it's deprecated, does not mean it's moved to Qt3Support :-)

    QHttp is part of the network module of Qt. So you must add to your .pro file:

    @
    QT += network
    @



  • Well, I am not using QT to programm, but Netbeans which seems not to use the pro-file. Anyway,
    @QT += network@ is already set in the pro file of the "Mapviewer"-example I am trying to compile.
    Here are the paths netbeans analizes:
    @
    /home/konstantin/Desktop/qmapcontrol/QMapControl
    /usr/include/qt4
    /usr/include/qt4/QtCore
    /usr/include/qt4/QtGui
    /home/konstantin/NetBeansProjects/mapsurf/
    Analyzed system include paths:
    /usr/include/c++/4.4
    /usr/include/c++/4.4/i686-linux-gnu
    /usr/include/c++/4.4/backward
    /usr/local/include
    /usr/lib/gcc/i686-linux-gnu/4.4.5/include
    /usr/lib/gcc/i686-linux-gnu/4.4.5/include-fixed
    /usr/include@

    For sure, I tried on QT too, but there seems to be a rather basic mistake in my Settings.When I try to compile, it says: Das "Programm konnte nicht gestartet werden. Möglicherweise stimmt der Pfad nicht oder die Berechtigungen sind sind ausreichend?"

    But I think I should concentrate on the QHttp problem.



  • I just noticed Netbeans also doesn't find QNetworkAccessManager. So I added /usr/include/qt4/ and some of it's subdirectories to my include list. There also is QHttp. I will tell if I succeed compiling.



  • Then you have to add /usr/include/qt4/QtNetwork to the list of include directories.



  • I did so, but it didn't help, as Netbeans couldn't find the binaries.
    But I found the solution: Rightclick the project in Netbeans, choose Build->Qt and check the QtNetwork-Box. This is the analogon to writing @QT += network@ in Qt.
    Now it compiles fine.

    Thank you for your help, it gave me the right idea.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.