Results 1 to 6 of 6

Thread: Qhttp:Post() - multipart/form-data

  1. #1
    Join Date
    Apr 2008
    Location
    California
    Posts
    25
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Qhttp:Post() - multipart/form-data

    Hello,

    I'm trying to do a HTTP Post of a multipart/form-data. The form code is as below:
    ================================================== ===
    <html>
    <pre>
    <form method="POST" enctype="multipart/form-data" action="http://beta.abc.com/app/submit.jsp">

    Username: <input type="text" name="user" value="arun">
    SHA1 encrypted pass: <input type="text" name="pass" value="1a27452283b0b46720913760f056377eb0b6388c">

    <input type="hidden" name="v" value="1.0">
    <input type="hidden" name="command" value="add">
    <input type="submit" name="submit" value="submit">

    </form>
    </pre>
    </html>
    ================================================== ===

    Here is my Qt Code:
    http = new QHttp(this);
    connect(http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),
    this, SLOT(readResponseHeader(const QHttpResponseHeader &)));
    connect(http, SIGNAL(readyRead(const QHttpResponseHeader&)),
    this, SLOT(readyRead(const QHttpResponseHeader&)));


    http->setHost("beta.abc.com");
    // Data
    QByteArray data;
    data.append(QString(QString("user=arun")+QString(" &pass=1a27452283b0b46720913760f056377eb0b6388c&v=1 .0&command=add")).toUtf8());

    QHttpRequestHeader header("POST", "/app/submit.jsp");
    header.setValue("Host", "beta.abc.com");
    header.setContentType("multipart/form-data, boundary=AaB03x");
    header.setContentLength(data.length());
    http->request(header, data);
    =========================================
    For some reason the server doesn't like it and returns me an invalid username/ password error. I'm suspecting that I'm doing something wrong in the way I'm posting the data but not sure where the problem is.

    Any help would be greatly appreciated.

    thanks,
    - AR

  2. #2
    Join Date
    Apr 2008
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qhttp:Post() - multipart/form-data

    There is a space in your url, but you probably knew that " &pass..
    Please let me know if you get this sort of stuff working. (I am trying also)

  3. #3
    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: Qhttp:Post() - multipart/form-data

    Are you sure the data should be posted in such a format?

    This might help you: http://www.faqs.org/rfcs/rfc2388.html

    What you are using seems to be "application/x-url-encoded".

  4. #4
    Join Date
    Apr 2008
    Location
    California
    Posts
    25
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Qhttp:Post() - multipart/form-data (solved)

    Thank you for your responses. I found out the problem was the format of my post data. I also needed to add the end of the data text. If anyone is interested in knowing the solution I can post my code here.

    Once again thank you for your time.

    Ar
    - AR

  5. #5
    Join Date
    Oct 2010
    Location
    India
    Posts
    12
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Qhttp:Post() - multipart/form-data

    Hi, please post your Qt code here, It will be useful for our forum users.

  6. #6
    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: Qhttp:Post() - multipart/form-data

    Not using the deprecated QHttp class in new code would also be helpful.
    This class is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

Similar Threads

  1. QSqlQueryModel data update
    By psi in forum Qt Programming
    Replies: 4
    Last Post: 20th July 2012, 03:59
  2. Replies: 4
    Last Post: 19th October 2007, 19:47
  3. Data model
    By steg90 in forum Qt Programming
    Replies: 3
    Last Post: 17th September 2007, 12:14
  4. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.