-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Closed
Description
When i try send a request using httplib::Client::send(const httplib::Request& request)
, the params set via request.params.insert(...)
dissapear. But if I hardcode them in the request path, it will work. So, it looks like problem is in the request building
#include <iostream>
#include "cpp-httplib/httplib.h"
using namespace std;
int main() {
httplib::Server server;
server.Get("/", [](const httplib::Request& req, httplib::Response& response) {
if (req.has_param("test")) {
cout << "test=" << req.get_param_value("test") << endl;
} else {
cout << "No such param 'test'" << endl;
}
});
thread t([&]() { server.listen("localhost", 4444); });
sleep(1);
httplib::Client client("localhost", 4444);
httplib::Request request;
request.method = "GET";
request.path = "/";
request.params.insert(pair<string, string>("test", "testvalue"));
auto res = client.send(request);
cout << res->status << endl;
cout<<"-----------------------"<<endl;
request.path = "/?test=testvalue";
res = client.send(request);
cout << res->status << endl;
server.stop();
t.join();
return 0;
}
Output:
No such param 'test'
200
-----------------------
test=testvalue
200
Metadata
Metadata
Assignees
Labels
No labels