22 fwrite( data,1,n, stdout );
28 printf(
"COMPLETE (%d bytes)\n",
count );
35 puts(
"-----------------Test1------------------------" );
40 conn.
request(
"GET",
"/happyhttp/test.php", 0, 0,0 );
50 puts(
"-----------------Test2------------------------" );
53 const char* headers[] =
55 "Connection",
"close",
56 "Content-type",
"application/x-www-form-urlencoded",
57 "Accept",
"text/plain",
61 const char* body =
"answer=42&name=Bubba";
66 "/happyhttp/test.php",
68 (
const unsigned char*)body,
77 puts(
"-----------------Test3------------------------" );
80 const char* params =
"answer=42&foo=bar";
81 int l = strlen(params);
86 conn.
putrequest(
"POST",
"/happyhttp/test.php" );
89 conn.
putheader(
"Content-type",
"application/x-www-form-urlencoded" );
92 conn.
send( (
const unsigned char*)params, l );
101 puts(
"-----------------Test4------------------------" );
104 const char* params =
"--||||\nContent-Disposition: form-data; name=\"upfile\"; filename=\"testfile.txt\" \nContent-Type: application/octet-stream \n\nfile contents1\nfile contents2\nfile contents3\nfile contents4\nfile contents5\nfile contents6\nfile contents7\nfile contents8\nfile contents9\nfile contents10\n--||||--";
105 int l = strlen(params);
113 conn.
putheader(
"Content-Type",
"multipart/form-data; boundary=||||" );
114 conn.
putheader(
"Accept",
"text/plain" );
116 conn.
send( (
const unsigned char*)params, l );
130 puts(
"-----------------Test5------------------------" );
133 const char* params =
"--||||\nContent-Disposition: form-data; name=\"upfile\"; filename=\"testfile.txt\" \nContent-Type: application/octet-stream \n\nfile contents1\nfile contents2\nfile contents3\nfile contents4\nfile contents5\nfile contents6\nfile contents7\nfile contents8\nfile contents9\nfile contents10\n--||||--";
134 int l = strlen(params);
142 conn.
putheader(
"Content-Type",
"multipart/form-data; boundary=||||" );
143 conn.
putheader(
"Accept",
"text/plain" );
145 conn.
send( (
const unsigned char*)params, l );
157int main(
int argc,
char* argv[] )
161 int code = WSAStartup(MAKEWORD(1, 1), &wsaData);
164 fprintf(stderr,
"shite. %d\n",code);
179 fprintf(stderr,
"Exception:\n%s\n", e.
what() );
void request(const char *method, const char *url, const char *headers[]=0, const unsigned char *body=0, int bodysize=0)
void putheader(const char *header, const char *value)
void setcallbacks(ResponseBegin_CB begincb, ResponseData_CB datacb, ResponseComplete_CB completecb, void *userdata)
void send(const unsigned char *buf, int numbytes)
void putrequest(const char *method, const char *url)
const char * getreason() const
const char * what() const
void OnData(const happyhttp::Response *r, void *userdata, const unsigned char *data, int n)
int main(int argc, char *argv[])
void OnBegin(const happyhttp::Response *r, void *userdata)
void OnComplete(const happyhttp::Response *r, void *userdata)