How can I send Http request from QML?
-
Hi all,
I want to send http request to a server http://www.xxxxxxxxx.com/test/test.php
with the following parameters
name
email
messagehow can I do that in Qml?
thank you for your help
-
I'm almost sure that you have to use Qt for that, design you UI with QML and implement a method with Qt (using QNetwork module), then all the method from Qt, you can read about this in
http://doc.qt.nokia.com/4.7-snapshot/qml-extending-tutorial-index.html
http://doc.qt.nokia.com/4.7-snapshot/qtbinding.htmlEdit:
Basically you write a class that hinherits from QDeclarativeView, then you create an QDeclarativeContext and then you send the whole class to QML with@context->setContextProperty("Main", this);@
then in QML you can do
Main.method()
-
Hi,
From within QML you can use "XMLHttpRequest":http://doc.qt.nokia.com/4.7-snapshot/qdeclarativeglobalobject.html#xmlhttprequest to make network requests.
Regards,
Michael -
You can use the XMLHttpRequest (sorry @mbrasser , your link is outdated) which implements the W3C XMLHttpRequest API
So, all you need to do is:
var req = new XMLHttpRequest(); req.open("POST", "http://www.xxxxxxxxx.com/test/test.php"); req.onreadystatechange = function() { if (req.readyState == XMLHttpRequest.DONE) { // what you want to be done when request is successfull } } req.onerror = function(){ // what you want to be done when request failed }
Then when you want to send a request, just call :
req.send("name=xxx&email=xxx&message=xxx");