【发布时间】:2018-03-22 10:40:07
【问题描述】:
我正在调用带有 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”)?
【问题讨论】:
-
注意:重定向 cout 和 cerr 似乎不起作用。
标签: c++ curl http-headers httpresponse curlpp