我正在调用带有 JSON 有效负载的 REST WS 来订阅某些事件。服务器使用 HTTP-Code 201 和HTTP-Header 中名为Location的字段以及订阅的 ID 进行应答。
例如,在 curl (-v) 中,我们得到:
[...]
< HTTP/1.1 201 Created
< Connection: Keep-Alive
< Content-Length: 0
< Location: /v2/subscriptions/5ab386ad4bf6feec37ffe44d
[...]
在使用 curlpp 的 C++ 中,我们希望通过查看响应标头来检索该 ID。现在我们只有正文响应(在本例中为空)。
std::ostringstream response;
subRequest.setOpt(new curlpp::options::WriteStream(&response));
// Send request and get a result.
subRequest.perform();
cout << response.str() << endl;
我们如何使用 curlpp 在 C++ 中获取Location标头的字段(示例中的内容为“/v2/subscriptions/5ab386ad4bf6feec37ffe44d”)?