Results 1 to 11 of 11

Thread: Https POST Request

  1. #1
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Https POST Request

    Hi,

    I am trying to implement Google Account Authentication for Installed Apps using the API provided by google.

    http://code.google.com/apis/accounts...alledApps.html

    One of the requirement for this is to know how to make HTTPS POST requests and handle responses.

    Is there a Qt way to do this?

    Thanks a lot.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Https POST Request


  3. #3
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Https POST Request

    Thanks for your reply.

    The Qt Assistant doesn't talk anything about Https and therefore I got the doubt.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Https POST Request

    "s" stands for "secure", you need an SSL layer to have https. In Qt3 you can use a Qt Cryptographic Architecture (QCA - see our links section) or QtSSLSocket - a Qt Solution from Trolltech. With Qt4 you can use the Qt Solution as well. Alternatively you'll need to provide your own SSL layer implementation. The application layer (HTTP) remains the same.

  5. #5
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Https POST Request

    Quote Originally Posted by wysota View Post
    "s" stands for "secure", you need an SSL layer to have https.
    I am aware of that.

    Quote Originally Posted by wysota View Post
    In Qt3 you can use a Qt Cryptographic Architecture (QCA - see our links section) or QtSSLSocket - a Qt Solution from Trolltech. With Qt4 you can use the Qt Solution as well.
    oh, I thought Qt does that. Thanks for clarifying it.

    Quote Originally Posted by wysota View Post
    Alternatively you'll need to provide your own SSL layer implementation.
    openSSL will do, rite?

    Thanks a lot

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Https POST Request

    Quote Originally Posted by munna View Post
    oh, I thought Qt does that.
    Not out of the box.

    openSSL will do, rite?
    Yes, but you need to implement a layer which you can use to wrap Qt sockets into. That's essentially what QtSSLSocket does, but you have to pay for it.

  7. #7
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Https POST Request

    I found this python code which does not perform any kind of encryption

    Qt Code:
    1. import re, httplib2
    2.  
    3. h = httplib2.Http()
    4. auth_uri = 'https://www.google.com/accounts/ClientLogin'
    5. headers = {'Content-Type': 'application/x-www-form-urlencoded'}
    6. myrequest =
    7. "Email=YOUR_GMAIL_ADDRESS&Passwd=GMAIL_PASSWORD&service=blogger&service=Whatever-TestApp-0.0"
    8. response, content = h.request(auth_uri, 'POST', body=myrequest,
    9. headers=headers)
    10.  
    11. # Extract the auth token from the returned content, and print it to
    12. stdout.
    13. print re.search('Auth=(\S*)', content).group(1)
    To copy to clipboard, switch view to plain text mode 

    There is also similar perl code which does not perform any encryption.

    Will the correspoding Qt code work or will I still need to encrypt the data and then send ?

    I would be greatful to you if can explain this to me like I am a 4 year old kid, with some example.

    Thanks a lot.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Https POST Request

    How do you know the code doesn't perform encryption? Maybe the library does that transparently? You could just post a regular http request and see what happens...

  9. #9
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Https POST Request

    This is what I did

    Qt Code:
    1. connect(&http,SIGNAL(done(bool)),this,SLOT(httpDone(bool)));
    2. connect(&http,SIGNAL(readyRead(const QHttpResponseHeader &)),this,SLOT(readyRead(const QHttpResponseHeader &)));
    3.  
    4. http.setHost("www.google.com");
    5.  
    6. QString str = "Email=somename@gmail.com&Passwd=somepassword"
    7. "&service=cl&source=Gulp-CalGulp-1.05";
    8. QHttpRequestHeader header( "POST", "/accounts/ClientLogin") ;
    9. header.setValue("Host", "https://www.google.com") ;
    10. header.setContentType( "application/x-www-form-urlencoded" ) ;
    11. http.request(header,QVariant(str).toByteArray());
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void UpdateChecker::readyRead(const QHttpResponseHeader &header)
    2. {
    3. //QString str = header.reasonPhrase();
    4. result = QString(http.readAll().data());
    5. }
    To copy to clipboard, switch view to plain text mode 

    I got result as

    Qt Code:
    1. <HTML>
    2. <HEAD>
    3. <TITLE>Moved Temporarily</TITLE>
    4. </HEAD>
    5. <BODY BGCOLOR="#FFFFFF" TEXT="#000000">
    6. <H1>Moved Temporarily</H1>
    7. The document has moved <A HREF="https://https/accounts/ClientLogin">here</A>.
    8. </BODY>
    9. </HTML>
    To copy to clipboard, switch view to plain text mode 

    Probably Qt itself is generating this.

    Can you please give me some minimal example on how I encrypt the data and send ?

    Thanks a lot.

  10. #10
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Https POST Request

    I did one more experiment. Here it is

    Qt Code:
    1. <html>
    2. <body>
    3. <form action="https://www.google.com/accounts/ClientLogin" method="post">
    4.  
    5. <input type="hidden" name="service" value="cl" />
    6. <input type="hidden" name="source" value="some-app-1.0" />
    7.  
    8. Email :
    9. <input type="text" name="Email" />
    10. <br/>
    11. Password:
    12. <input type="password" name="Passwd" />
    13. <br/>
    14. <input type="submit" name="Submit" value="Login">
    15.  
    16. </form>
    17. </body>
    18. </html>
    To copy to clipboard, switch view to plain text mode 

    The response to this was what google sends and this code works correctly.

    Isn't this similar to the code above?

    Maybe I have got the basics itself wrong.

    Please help.
    Thanks a lot

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Https POST Request

    The problem is that QHttp doesn't handle https (SSL). Without introducing the SSL layer you won't be able to send a https request.

Similar Threads

  1. X Error of failed request - on exit
    By VorosM in forum Newbie
    Replies: 3
    Last Post: 12th April 2006, 09:22

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.