2
0

simple_request.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * example for httpclientlite.hxx
  3. */
  4. #include <iostream>
  5. #include <map>
  6. #include <string>
  7. #include <jdl/httpclientlite.h>
  8. using namespace jdl;
  9. int main(int argc, char *argv[]) {
  10. if (argc == 1) {
  11. std::cout << "Use " << argv[0] << " http://example.org" << std::endl;
  12. return EXIT_SUCCESS;
  13. }
  14. HTTPResponse response = HTTPClient::request(HTTPClient::POST, URI(argv[1]));
  15. if (!response.success) {
  16. std::cout << "Request failed!" << std::endl;
  17. return EXIT_FAILURE;
  18. }
  19. std::cout << "Request success" << endl;
  20. std::cout << "Server protocol: " << response.protocol << std::endl;
  21. std::cout << "Response code: " << response.response << std::endl;
  22. std::cout << "Response string: " << response.responseString << std::endl;
  23. std::cout << "Headers:" << std::endl;
  24. for (stringMap::iterator it = response.header.begin(); it != response.header.end(); ++it) {
  25. std::cout << "\t" << it->first << "=" << it->second << std::endl;
  26. }
  27. std::cout << response.body << std::endl;
  28. return EXIT_SUCCESS;
  29. }