HTTP GET request

I have a function that performs HTTP GET request.
It works, BUTT....
I need the url like this: www.mywebsite.com/myscript.php?data=blabla
But if I do that the request fails...
How do I implememnt this?
Request to a script, instead of main page...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
void HttpDisplayData(void)
{
	WSADATA wsaData;
	if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
		cout << "WSAStartup failed.\n";
		return;
	}
	SOCKET Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	struct hostent *host;
	host = gethostbyname("www.paperclip.netai.net");
	SOCKADDR_IN SockAddr;
	SockAddr.sin_port = htons(80);
	SockAddr.sin_family = AF_INET;
	SockAddr.sin_addr.s_addr = *((unsigned long*)host->h_addr);
	cout << "Connecting...\n";
	if (connect(Socket, (SOCKADDR*)(&SockAddr), sizeof(SockAddr)) != 0){
		cout << "Could not connect";
		return;
	}
	cout << "Connected.\n";
	const char link[] = "www.paperclip.netai.net";
	send(Socket, "GET / HTTP/1.1\r\nHost: www.paperclip.netai.net \r\nConnection: close\r\n\r\n", strlen("GET / HTTP/1.1\r\nHost: www.paperclip.netai.net \r\nConnection: close\r\n\r\n"), 0);
	char buffer[10000];
	int nDataLength;
	while ((nDataLength = recv(Socket, buffer, 10000, 0)) > 0){
		int i = 0;
		while (buffer[i] >= 32 || buffer[i] == '\n' || buffer[i] == '\r') {
			cout << buffer[i];
			i += 1;
		}
	}
	closesocket(Socket);
	WSACleanup();
	return;
}

P.S. if you still don't understand the question, read line 22 of the code
Last edited on
If you think of an HTTP URL being of the form http://<host><path> , where the path defaults to /, then your request: www.mywebsite.com/myscript.php?data=blabla
breaks down to
1
2
host=www.mywebsite.com
path=/myscript.php?data=blabla

To make that request in code, you do a DNS lookup on www.mywebsite.com, and your request looks like:
 
GET /myscript.php?data=blabla HTTP/1.1\r\nHOST: www.mywebsite.com\r\n\r\n

There's an example here: http://www.boost.org/doc/libs/1_47_0/doc/html/boost_asio/overview/networking/iostreams.html
Last edited on
nevermind, I solved it even before you answered, damn I hate myself
Topic archived. No new replies allowed.