You are not logged in.

mikhailt

Beginner

  • "mikhailt" is male
  • "mikhailt" started this thread

Posts: 10

Location: Norge

Occupation: software engineer

  • Send private message

1

Tuesday, September 12th 2006, 11:05pm

Qhttp::request() method and GET request

It looks like Qhttp::request(const QHttpRequestHeader &header, QIODevice* data, QIODevice *to)
method does not send request parameters for GET request.

Method Qhttp::request(header,data ...) sends a request type defined in header.
And this can be POST,GET etc.

Qhttp::request(header,data ...) should send request parameters as data variable. It is OK for POST.
But it does not send it for GET ?(

I do not want to use Qhttp::get() method because I need to send a special defined request header to server.

This post has been edited 1 times, last edit by "mikhailt" (Sep 12th 2006, 11:05pm)


moogle

Beginner

  • "moogle" is male

Posts: 21

Location: Sweden

Occupation: Developer

  • Send private message

2

Wednesday, September 13th 2006, 1:04am

Use QTcpSocket instead.

qt 4:

Very simplified example without signals & slots for stateChanges implemented.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Requestheader goes in here
QByteArray *buf = new QByteArray("GET / HTTP/1.1\r\nHost: host.com\r\nConnection: close\r\n\r\n");

// Connection to host
QTcpSocket *sock = new QTcpSocket();
sock->connectToHost("host.com",80,QIODevice::ReadWrite);
sock->write(buf->data(),buf->length());

// implement check for data available to be recieved.
x
x
x

// clear the buffer and read all available data from socket.
buf->clear();
buf->append(sock->readAll());
sock->disconnectFromHost();

// response goes into buf.

This post has been edited 2 times, last edit by "moogle" (Sep 13th 2006, 10:57pm)


mikhailt

Beginner

  • "mikhailt" is male
  • "mikhailt" started this thread

Posts: 10

Location: Norge

Occupation: software engineer

  • Send private message

3

Thursday, September 14th 2006, 10:00pm

Thank you moogle,
I will consider this possibility

But I think it should be a way to send GET parameters through Qhttp::request()

moogle

Beginner

  • "moogle" is male

Posts: 21

Location: Sweden

Occupation: Developer

  • Send private message

4

Thursday, September 14th 2006, 10:32pm

Okay, so the only thing you want to do is send a GET-parameter?

Why can´t you do it with QHttp?

Source code

1
2
3
4
5
6
7
8
QHttp *http = new QHttp();
QFile file("recv.txt");
if (file.open(QIODevice::WriteOnly)) {
    http->setHost("www.host.com",80);
    http->get("/path/to/url.php?id=100&s=10",&file);
    file.close();
    http->closeConnection();
}



Sends $_GET["id"] (= 100) and $_GET["s"] (= 10) to a phpscript.

This post has been edited 2 times, last edit by "moogle" (Sep 15th 2006, 1:03pm)


mikhailt

Beginner

  • "mikhailt" is male
  • "mikhailt" started this thread

Posts: 10

Location: Norge

Occupation: software engineer

  • Send private message

5

Friday, September 15th 2006, 11:23am

moogle,

Quoted

Okay, so the only thing you want to do is send a GET-parameter?
Why can´t you do it with QHttp?

Not the only,
I need to send GET parameters with customized HTTP header.
That's why I need to use Qhttp::request(header,...)

Qhttp::get() sends it's own header, that can not be customised.

The problem is that Qhttp::request() does not send GET request parameters, as it is axpected. It has a bug :(

Well, it looks like QTcpSocket is the only choise.

mikhailt

Beginner

  • "mikhailt" is male
  • "mikhailt" started this thread

Posts: 10

Location: Norge

Occupation: software engineer

  • Send private message

6

Friday, September 15th 2006, 12:25pm

I have found the solution!

When the custom request header is being constructed for GET request,
then all request parameters must be added there (to strPath).
As a string like "?aaa=123&ccc=456"

QString strPath = strRealURLPath;
if (GET == strRequestType) strPath += "?aaa=123&ccc=456";
QHttpRequestHeader* pHeader = new QHttpRequestHeader(strRequestType, strPath);

It should not be done for POST request.

Then we can send both POST and GET requests with custom header and request parameters through Qhttp::request() method.