#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <conio.h>
#include <winsock.h>
#include <io.h>
#define HTTP_PORT 80
void main()
{
int sock;
struct sockaddr_in host_addr;
struct hostent *hostinfo;
char host[200], file[200];
char command[3000];
char buf[1024];
unsigned int bytes_sent, bytes_recv;
strcpy(host, "thehost.de");
strcpy(file, "/asdf.fcgi?argument=123");
WSADATA wsaData;
if (WSAStartup (MAKEWORD(1, 1), &wsaData) != 0) {
fprintf (stderr, "WSAStartup(): Kann Winsock nicht initialisieren.\n");
getch();
exit (EXIT_FAILURE);
}
sock = socket (AF_INET, SOCK_STREAM, 0);
printf("sock");
if (sock == -1) {
perror ("socket()");
getch();
exit (EXIT_FAILURE);
}
memset( &host_addr, 0, sizeof (host_addr));
host_addr.sin_family = AF_INET;
host_addr.sin_port = htons (HTTP_PORT);
host_addr.sin_addr.s_addr = inet_addr (host);
if (host_addr.sin_addr.s_addr == INADDR_NONE) {
hostinfo = gethostbyname (host);
if (hostinfo == NULL) {
perror ("gethostbyname()");
getch();
exit (EXIT_FAILURE);
}
memcpy((char*) &host_addr.sin_addr.s_addr, hostinfo->h_addr, hostinfo->h_length);
}
if (connect(sock, (struct sockaddr *) &host_addr, sizeof(struct sockaddr)) == -1) {
perror ("connect()");
getch();
exit (EXIT_FAILURE);
}
printf("connect");
sprintf (command, "GET %s HTTP/1.1\nHost: %s\n\n", file, host);
bytes_sent = send (sock, command, strlen (command), 0);
printf("send");
if (bytes_sent == -1) {
perror ("send()");
getch();
exit (EXIT_FAILURE);
}
while ((bytes_recv = recv (sock, buf, sizeof(buf), 0)) > 0) {
write (1, buf, bytes_recv);
}
printf("recv");
if (bytes_recv == -1) {
perror ("recv()");
getch();
exit (EXIT_FAILURE);
}
printf ("\n");
closesocket(sock);
WSACleanup();
}