[Qt-interest] QNetworkAccessManager file upload and uri encode

Diego Schulz dschulz at gmail.com
Wed May 20 21:45:06 CEST 2009


On Wed, May 20, 2009 at 2:51 PM, Wagner Ferreira Soares
<wagner.fsoares at gmail.com> wrote:
> I've managed to create an application that can communicate with a webhost.
> I can do a post within my application, send some text to the server, receive
> the result information and print it with a messagebox.
> The problem is, some characters cause problems when I'm sending the text
> (i.e. &, ', ", \ ), in javascript I can use "encodeURIComponent" so what
> could I use in Qt4?
>
> And what about file uploading? how could I send a file with
> QNetworkAccessManager? The browser is responsible for sending binary "text"
> to the server when I choose a file and click on submit, how can I do it in
> Qt4?
>
> my actual send code:
>
> QByteArray data;
> data.append("r=test");
> QUrl url("http://localhost/test.php");
> QNetworkRequest qnr(url);
> QNetworkAccesManager *qnam = new QNetworkAccesManager(this); /* this line
> isn't actually here, I placed it here just to show what qnam is! */
> qnam->post(qnr, data);
>
> thanks
>

IIRC QUrl has the methods you are looking for. Take a look at the docs.

regards,

diego



More information about the Qt-interest-old mailing list