Results 1 to 3 of 3

Thread: How to make SMS Getaway works using QHttp .

  1. #1
    Join Date
    Oct 2009
    Location
    London
    Posts
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to make SMS Getaway works using QHttp .

    Hi All

    I'm working on SMS Getaway system. which works.
    I'm using the SMS Getaway system using Http

    I did make it work on C# like this code..

    Qt Code:
    1. // Get Balance from Mobily.ws API Balance ..
    2. private string GetBalance()
    3. {
    4. HttpWebRequest req =(HttpWebRequest)WebRequest.Create("http://www.mobily.ws/api/balance.php?mobile="+MobilyUserName+"&password="+MobilyPassword);
    5. WebResponse resp = req.GetResponse();
    6.  
    7. Stream s = resp.GetResponseStream();
    8. StreamReader sr= new StreamReader(s, Encoding.ASCII);
    9. String doc = sr.ReadToEnd();
    10.  
    11. return doc;
    12. }
    To copy to clipboard, switch view to plain text mode 

    but using Qt is not working..

    Qt Code:
    1. QString mainDialog::getBalance()
    2. {
    3.  
    4. http = new QHttp(this);
    5. connect(http, SIGNAL(readyRead(const QHttpResponseHeader &)), this, SLOT(readGetBalanceData(const QHttpResponseHeader &)));
    6. QString getBalancelink = "http://www.mobily.ws/api/balance.php?mobile=" + MobilyUserName + "&password=" + MobilyPassword ;
    7. QUrl url(getBalancelink);
    8.  
    9. QByteArray byteArray;
    10. http->setHost(url.host());
    11. QHttpRequestHeader header("POST" ,"/api/balance.php?mobile=" + MobilyUserName + "&password=" + MobilyPassword);
    12. header.setValue("Host", "http://www.mobily.ws");
    13. header.setValue("Content-Type", "application/x-www-form-urlencoded");
    14. http->request(header,byteArray);
    15. http->close();
    16.  
    17. QString str = QString(byteArray);
    18. return str ;
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 


    And sending message in C# is working as in this code

    Qt Code:
    1. // This Method let you send Message
    2. private void sendMessage()
    3. {
    4. HttpWebRequest req =(HttpWebRequest)WebRequest.Create("http://www.mobily.ws/api/msgSend.php");
    5. String s1 = "mobile=" + MobilyUserName + "&password=" + MobilyPassword + "&numbers=" + textBoxNumbers.Text + "&sender=" + textBoxSender.Text + "&msg=" + convertToUnicode(textBoxMessage.Text) + "&applicationType=24";
    6. req.Method = "POST";
    7. req.ContentType = "application/x-www-form-urlencoded";
    8.  
    9. Byte[] byteArray = Encoding.UTF8.GetBytes(s1);
    10. req.ContentLength = byteArray.Length;
    11. Stream dataStream= req.GetRequestStream();
    12. dataStream.Write(byteArray, 0, byteArray.Length);
    13. dataStream.Close();
    14. WebResponse resp= req.GetResponse();
    15.  
    16. Stream s = resp.GetResponseStream();
    17. StreamReader sr = new StreamReader(s, Encoding.ASCII);
    18. String doc = sr.ReadToEnd();
    19.  
    20. showResult(doc);
    21. }
    To copy to clipboard, switch view to plain text mode 

    But for QT is not..

    Qt Code:
    1. void mainDialog::sendMessage()
    2. {
    3. http = new QHttp(this);
    4. connect(http, SIGNAL(done(bool)), this, SLOT(showResult()));
    5. http->setHost("http://www.mobily.ws");
    6. QString s1 = "mobile=" + MobilyUserName + "&password=" + MobilyPassword + "&numbers=" + plainTextEditNumbers->toPlainText() + "&sender=" + lineEditSender->text() + "&msg=" + plainTextEditMessage->toPlainText()+ "&applicationType=24";
    7. http->get(s1);
    8. }
    To copy to clipboard, switch view to plain text mode 


    I do not know if I'm messing any Objects in QT .... I'm using the SMS Getaway system using Http

    Best Regards
    Rajab Natshah
    rajab.natshah.com

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to make SMS Getaway works using QHttp .

    The Qt calls are asynchronous. You need to use signals and slots.

  3. #3
    Join Date
    Oct 2009
    Location
    London
    Posts
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make SMS Getaway works using QHttp .

    Hi fatjuicymole

    Thanks for the quick replay,

    I have been working with QHttp to download PDF and html files form websites.

    but to get the data to QString is not working.

    I do not know if i can get any example to get data to QString ..

    Best Regards
    Rajab Natshah
    rajab.natshah.com

Similar Threads

  1. Replies: 11
    Last Post: 20th January 2009, 14:10
  2. how to make QHttp work with this URL
    By ber_44 in forum Qt Programming
    Replies: 11
    Last Post: 23rd April 2007, 09:20
  3. trying to make QHttp synchronous or threaded
    By ber_44 in forum Qt Programming
    Replies: 15
    Last Post: 16th April 2007, 01:56
  4. [Qt4 QHttp] can't make it work
    By rodo in forum Qt Programming
    Replies: 3
    Last Post: 10th April 2007, 17:33
  5. How to make QHttp detect a disconnect?
    By gfunk in forum Qt Programming
    Replies: 1
    Last Post: 7th February 2007, 10:07

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.