2
0

testclient.c 732 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include <scgi.h>
  2. int main(int argc, char *argv[])
  3. {
  4. char buf[16336] = "";
  5. ssize_t len;
  6. scgi_handle_t handle = { 0 };
  7. char *ip;
  8. int port = 0;
  9. if (argc < 2) {
  10. fprintf(stderr, "usage: testclient <ip> <port>\n");
  11. exit(-1);
  12. }
  13. ip = argv[1];
  14. port = atoi(argv[2]);
  15. scgi_add_param(&handle, "REQUEST_METHOD", "POST");
  16. scgi_add_param(&handle, "REQUEST_URI", "/deepthought");
  17. scgi_add_param(&handle, "TESTING", "TRUE");
  18. scgi_add_param(&handle, "TESTING", "TRUE");
  19. scgi_add_body(&handle, "What is the answer to life?");
  20. scgi_connect(&handle, ip, port, 10000);
  21. scgi_send_request(&handle);
  22. while((len = scgi_recv(&handle, buf, sizeof(buf))) > 0) {
  23. printf("READ [%s]\n", buf);
  24. }
  25. scgi_disconnect(&handle);
  26. }