summaryrefslogtreecommitdiffstats
path: root/test/nanohttp.c
blob: 78d9fdaeb0d36570ff324b2e5b0c4d1c8d75b0dd (plain) (blame)
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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <libxml/nanohttp.h>
#define UA "Nokia WAP Gateway 4.1 CD1/ECD13_D/4.1.04)"
int main (int argc, char ** argv) {
	if (argc < 1+1) {
		fprintf(stderr, "%s <URL>\n", argv[0]);
		return 1;
	}
	char * contentType = NULL;
	char * redir = NULL;
	int readstatus = 0;
	char buf[4096];
	/* xmlNanoHTTPInit(); */
	void * r = xmlNanoHTTPMethodRedir(argv[1], "GET", NULL /* inp */, &contentType, &redir, "User-Agent: " UA "\r\n", 0 /* inplen */);
	if (!r) {
		fprintf(stderr, "!r\n");
		return 1;
	}
	if (xmlNanoHTTPReturnCode(r) != 200)
		fprintf(stderr, "xmlNanoHTTPReturnCode(r) != 200\n");
	while ((readstatus = xmlNanoHTTPRead(r, buf, 4096)) > 1)
		write(1, buf, readstatus);
	if (readstatus == -1)
		fprintf(stderr, "readstatus == -1\n");
	xmlNanoHTTPClose(r);
	free(contentType);
	free(redir);
	/* xmlNanoHTTPCleanup(); */
	return 0;
}