Results 1 to 3 of 3

Thread: Http request encoding

  1. #1
    Join Date
    Mar 2009
    Posts
    29
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Http request encoding

    Hi, i have difficulty with encoding http request by function toEncoded(), it encode only some characters.
    It's my code:
    Qt Code:
    1. request.setUrl(QUrl(sUrl));
    2. QUrl postData;
    3. postData.addQueryItem("ctl00$MainContent$txtHashes", lHashes);
    4. postData.addQueryItem("ctl00$MainContent$txtCaptcha", sCaptcha);
    5. postData.addQueryItem("__VIEWSTATE", this->sViewState);
    6. postData.addQueryItem("__EVENTVALIDATION", this->sEventValidation);
    7. postData.addQueryItem("ctl00$MainContent$btnDecrypt", " Decrypt Hashes ");
    8. reply = manager->post(request, postData.toEncoded());
    To copy to clipboard, switch view to plain text mode 
    When return the postData.toEncoded(), it doeasn't change some characters, for example '/' or '$'. I don't know why this function doesn't work correctly.
    In result i receive error source page:
    Qt Code:
    1. <html><head><title>Object moved</title></head><body>
    2. <h2>Object moved to <a href="/error.aspx?aspxerrorpath=/sha1-decrypt.aspx">here</a>.</h2>
    3. </body></html>
    To copy to clipboard, switch view to plain text mode 
    I wait for some idea to resolve my problem.
    Last edited by Trok; 29th September 2011 at 23:01.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: Http request encoding

    The function works correctly. You're just incorrectly assuming you should be using it for the purpose you are using it for. Maybe you wanted to use toPercentEncoding()?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Http request encoding

    The error response from the upstream server is of precisely no use. Without an actual example of the data you claim is mis-encoded and how you are handling it we can just guess what is going wrong.

    According to RFC 3986, which QUrl implements, the following characters are permitted in a query string component:
    query = *( pchar / "/" / "?" )
    pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
    sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
    and then Section 2.4 kicks in:
    Under normal circumstances, the only time when octets within a URI
    are percent-encoded is during the process of producing the URI from
    its component parts. This is when an implementation determines which
    of the reserved characters are to be used as subcomponent delimiters
    and which can be safely used as data.
    For URL query strings only the '&' and '=' are used as a sub-component delimiters and therefore must be encoded if part of the data. So '$', '/', and most other characters from the "reserved" set are perfectly fine unencoded in this context.

    If you wish to do some funky encoding of your own then feel free. You can use QUrl::addEncodedQueryItem() to put these into the QUrl.

  4. The following user says thank you to ChrisW67 for this useful post:

    Trok (30th September 2011)

Similar Threads

  1. Http request
    By kars in forum Newbie
    Replies: 3
    Last Post: 31st August 2011, 10:15
  2. How to make a HTTP request in QTJambi
    By divanshu in forum Newbie
    Replies: 2
    Last Post: 28th June 2011, 06:29
  3. HTTP request
    By Trok in forum Qt Programming
    Replies: 9
    Last Post: 5th January 2010, 14:49
  4. http POST with form encoding
    By srikanth_trulyit in forum Qt Programming
    Replies: 1
    Last Post: 10th June 2009, 10:16
  5. http request
    By yagabey in forum Qt Programming
    Replies: 3
    Last Post: 28th December 2008, 19:19

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.