QNetworkAccessManager && http example
-
Hi all,
I'm trying to send sms from my application using an sms provider over internet (smsmobile.it) .They allow me to send sms by putting this string in a browser:
And it works fine using firefox.
Now I'm trying with the "http" example in qt 4.7 source (examples/network/http).
It doesn't works but the problem is with the "rcpt" parameter. As you can see in the link I posted, there is a "+" (plus) character but I wrote the sequence "% 2 b" (without space).
It seems like if the "% 2 b" sequence isn't recognized by QNetworkAccessManager in the url. -
This should do the trick:
@
QUrl url2("http://sms.smsmobile-ba.com/sms/send.php");
url2.addQueryItem("user", "username");
url2.addQueryItem("pass", "password");
url2.addEncodedQueryItem("rcpt", QUrl::toPercentEncoding("+39333XXXXXXX"));
url2.addQueryItem("data", "message_text");
url2.addQueryItem("sender", "sender_name");
url2.addQueryItem("y", "a");
qDebug() << url2;
qDebug() << url2.toEncoded();// QUrl( "http://sms.smsmobile-ba.com/sms/send.php?user=username&pass=password&rcpt=+39333XXXXXXX&data=message_text&sender=sender_name&y=a" )
//"http://sms.smsmobile-ba.com/sms/send.php?user=username&pass=password&rcpt=+39333XXXXXXX&data=message_text&sender=sender_name&y=a"@
-
@Volker: You answered to a question I was though before I post the question :) Great!
@Luca: If you are interested to a common share of the experience to manage a non-standard web application you can join also the "Naijanimi Free SMS":https://projects.forum.nokia.com/naijanimi project I'm setting up (take a look to the API specifications I am writing now on the project wiki).
-
[quote author="Volker" date="1299759052"]This should do the trick:
@
QUrl url2("http://sms.smsmobile-ba.com/sms/send.php");
url2.addQueryItem("user", "username");
url2.addQueryItem("pass", "password");
url2.addEncodedQueryItem("rcpt", QUrl::toPercentEncoding("+39333XXXXXXX"));
url2.addQueryItem("data", "message_text");
url2.addQueryItem("sender", "sender_name");
url2.addQueryItem("y", "a");
qDebug() << url2;
qDebug() << url2.toEncoded();// QUrl( "http://sms.smsmobile-ba.com/sms/send.php?user=username&pass=password&rcpt=+39333XXXXXXX&data=message_text&sender=sender_name&y=a" )
//"http://sms.smsmobile-ba.com/sms/send.php?user=username&pass=password&rcpt=+39333XXXXXXX&data=message_text&sender=sender_name&y=a"@[/quote]
It solved the problem!
Thanks.
-
Actually it's that server that sends short text messages.
Parameters added to the url are the way of submitting HTML forms with GET method.
http://www.w3.org/TR/html401/interact/forms.html#submit-format
I'm 99.99% sure that that server must not use GET in this case, but let's not open a flame against PHP developers.
-
One moment please,
You should use QNetwrokAccessManager in new Qt codding tradition, shouldn't you?
It is not enought to use only QUrl - there is no methods to send to server anything?bq. I’m 99.99% sure that that server must not use GET in this case, but let’s not open a flame against PHP developers.
Anything against any real developer for good.
-
[quote author="Pavel Mazniker" date="1300201920"]You should use QNetwrokAccessManager in new Qt codding tradition, shouldn't you?[/quote]
Yes. And it has nothing to do with "coding tradition" (which I interpret as "coding conventions"). QUrl is a container for URLs only and is fed to QNetworkAccessManager.
-
bq. Yes. And it has nothing to do with “coding tradition” (which I interpret as “coding conventions”). QUrl is a container for URLs only and is fed to QNetworkAccessManager.
I mean some of developers advice to use the manager and not the QHttp after some new Qt version, that means tradition, but convention is will more than do.
So using one of QNetworkAccessManager methods you get your sms sent? -
[quote author="Pavel Mazniker" date="1300205130"]bq. Yes. And it has nothing to do with “coding tradition” (which I interpret as “coding conventions”). QUrl is a container for URLs only and is fed to QNetworkAccessManager.
I mean some of developers advice to use the manager and not the QHttp after some new Qt version, that means tradition, but convention is will more than do.
So using one of QNetworkAccessManager methods you get your sms sent?[/quote]Dunno. Maybe you have a look at the example the OP mentioned:
bq. Now I’m trying with the “http” example in qt 4.7 source (examples/network/http).
-
[quote author="Pavel Mazniker" date="1300205130"]So using one of QNetworkAccessManager methods you get your sms sent?[/quote]
Errr... If you have a provider that provides such an API on the net, sure. It is not like QNetworkAccessManagers actually sends an SMS, it just sends a request to a webserver that offers an API that can send an SMS, probably to a selected range of numbers or with other restrictions. -
Sure, and not in all the cases the provider - sigh - offers an api.
If you are interested follow the development (soruces, wiki, doc etc) of the project Naijanimi SMS that you find at http://project.forum.nokia.com/naijanimi
It's a similar question. The api are yet documented in the wiki pages of the project and unfortunately don't return a xml answer but strings.
-
[quote author="Andre" date="1300206235"]
[quote author="Pavel Mazniker" date="1300205130"]So using one of QNetworkAccessManager methods you get your sms sent?[/quote]
Errr... If you have a provider that provides such an API on the net, sure. It is not like QNetworkAccessManagers actually sends an SMS, it just sends a request to a webserver that offers an API that can send an SMS, probably to a selected range of numbers or with other restrictions.[/quote]
Exactly, I'm using "www.smsmobile.it":http://www.smsmobile.it but there are a lot of other sms provider that works the same way.
-
[quote author="sushant" date="1410097638"]how to send a sms usng way2sms or site2sms or 160by2 using Qt[/quote]
Sorry but I don't know your sms provider. You should ask to the provider.
In my case, smsmobile provided me an HTTP protocol to use. As described on previous messages.