Skip to content

Instantly share code, notes, and snippets.

@yangacer
Created May 2, 2011 13:33
Show Gist options
  • Save yangacer/951614 to your computer and use it in GitHub Desktop.
Save yangacer/951614 to your computer and use it in GitHub Desktop.
Send request via evhttp (1.4)
void onCompleted(evhttp_request *req, void* arg)
{
fprintf(stderr, "Request completed\n");
fwrite(req->input_buffer->buffer, 1, req->input_buffer->off, stderr);
fprintf(stderr, "\n");
}
int main(int argc, char **argv)
{
char const *address = argv[1];
short port = atoi(argv[2]);
char *remote_addr(0);
unsigned short remote_port;
event_init();
evhttp_request *req = evhttp_request_new(&onCompleted, (void*)0);
evhttp_connection* conn = evhttp_connection_new(address, port);
evhttp_add_header(req->output_headers, "Accept", "text/html");
evhttp_add_header(req->output_headers, "Host", "yangacer.twbbs.org");
evhttp_make_request(conn, req, EVHTTP_REQ_GET, "/");
event_dispatch();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment