4

I'm a new User of POCO and could get HTTP response after HTTP::Request.

By the way, How do I create HTTP request with some parameters? For example, I want to set URI, http://xxxx/index.html?name=hoge&id=fuga&data=foo.

Of course I know it's possible if I set this uri directly. But I want to realize this like below. Does anyone know this way?

URI uri("http://xxx/index.html");
uri.setParam("name", "hoge");
uri.setParam("id", "fuga");
uri.setParam("data", "foo");
Christian Severin
  • 1,793
  • 19
  • 38
jef
  • 3,890
  • 10
  • 42
  • 76

1 Answers1

7

If you had looked up the documentation for Poco::URI, you'd see it's done with uri.addQueryParameter("name", "value"):

void addQueryParameter(
    const std::string & param,
    const std::string & val = ""
);

Adds "param=val" to the query; "param" may not be empty. If val is empty, only '=' is appended to the parameter.

In addition to regular encoding, function also encodes '&' and '=', if found in param or val.

You can also set all the parameters with setQueryParameters.

Unfortunately, Poco doesn't let you set the value of an existing query parameter (or remove it). If you want to do that, you have to clear the query portion of the URI and readd all the parameters you want with their values.

Cornstalks
  • 37,137
  • 18
  • 79
  • 144