PDA

View Full Version : Qhttp:Post() - multipart/form-data



arunredi
11th April 2008, 05:38
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,

louis_xx
12th April 2008, 10:25
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)

wysota
13th April 2008, 17:20
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".

arunredi
16th April 2008, 04:47
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

raja26
20th September 2011, 11:41
Hi, please post your Qt code here, It will be useful for our forum users.

ChrisW67
20th September 2011, 20:02
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.