Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing query pararm in httplib::Client::send #1985

Closed
AverageBeerEnjoyer opened this issue Nov 25, 2024 · 1 comment
Closed

missing query pararm in httplib::Client::send #1985

AverageBeerEnjoyer opened this issue Nov 25, 2024 · 1 comment

Comments

@AverageBeerEnjoyer
Copy link

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
yhirose added a commit that referenced this issue Nov 27, 2024
@yhirose
Copy link
Owner

yhirose commented Nov 27, 2024

@AverageBeerEnjoyer thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants