C++ wrapper for the Mastodon API
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

example15_proxy.cpp 949B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* This file is part of mastodon-cpp.
  2. * This example shows how to use a proxy.
  3. */
  4. #include <iostream>
  5. #include <vector>
  6. #include <string>
  7. #include <cstdint>
  8. #ifdef MASTODON_CPP
  9. #include "mastodon-cpp.hpp"
  10. #else
  11. #include <mastodon-cpp/mastodon-cpp.hpp>
  12. #endif
  13. using std::cout;
  14. using Mastodon::API;
  15. int main(int argc, char *argv[])
  16. {
  17. if (argc < 3)
  18. {
  19. std::cerr << "usage: " << argv[0] << " <instance> <access token>\n";
  20. return 1;
  21. }
  22. Mastodon::API masto(argv[1], argv[2]);
  23. // SOCKS5 Proxy. Proxy resolves URL hostname.
  24. masto.set_proxy("socks5h://[fd12::1a]:1080/");
  25. // HTTPS proxy with username and password
  26. masto.set_proxy("https://localhost:3128", "user5:supersecurepassword");
  27. std::string answer;
  28. std::uint16_t ret;
  29. ret = masto.get(API::v1::accounts_verify_credentials, answer);
  30. cout << "Return code: " << ret << '\n';
  31. std::cout << answer << '\n';
  32. return 0;
  33. }