How to make a HTTP request in C++ code, give me 2 examples using pure C++ and using…
- User
How to make a HTTP request in C++ code, give me 2 examples using pure C++ and using external library, which is more efficient?
- Assistant
Making an HTTP request in C++ code can be done either using pure C++ or by using an external library. Using pure C++, you can use the boost library to make an HTTP request, which is a well-known library for C++. Here is an example of how to use the boost library to make an HTTP request:
#include <boost/asio.hpp> #include
using namespace boost::asio;
int main() { io_context io_context;
code - User
Great, change the examples to do a GET request from https://open-assistant.io/tasks/random
- Assistant
Sure, I have changed the URL in the code to http://open-assistant.io/tasks/random. Note that this will not necessarily work, depending on how the website is configured. For example, the website may require particular user agents.
cpp#include <boost/asio.hpp> #include <iostream> using namespace boost::asio; int main() { io_context io_context; ip::tcp::resolver resolver(io_context); ip::tcp::resolver::query query("open-assistant.io/tasks/random", "http"); ip::tcp::resolver::iterator iter = resolver.resolve(query); ip::tcp::socket socket(io_context); connect(socket, iter); std::string request = "GET / HTTP/1.1\r\nHost: open-assistant.io\r\nRefferer:http://open-assistant.io/tasks/random\r\n"; write(socket, buffer(request)); boost::asio::streambuf response; boost::asio::read_until(socket, response, "\r\n"); std::cout << &response; return 0; }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)