【发布时间】:2018-04-17 01:47:49
【问题描述】:
我有 api https://api.gm-system.net/api/authenticate/searchStaffs/searchText,它返回一个人员列表。
这是我使用 cpprestsdk 和 c++ 访问此 api 的代码。
auto fileStream = std::make_shared<ostream>();
// Open stream to output file.
pplx::task<void> requestTask = fstream::open_ostream(U("results.html")).then([=](ostream outFile)
{
*fileStream = outFile;
// Create http_client to send the request.
http_client client(U("https://api.gm-system.net/api/authenticate/searchStaffs/michael"));
return client.request(methods::GET);
})
// Handle response headers arriving.
.then([=](http_response response)
{
......
}
如果没问题的话。但是我只是手动输入"michael" searchText。
我怎样才能让它接受任何类似这样的 searchText。
void MyTest(std::string searchText)
{
..... code here
// Create http_client to send the request.
http_client client(U("https://api.gm-system.net/api/authenticate/searchStaffs/" + searchText));
return client.request(methods::GET);
..... code here
}
我已经试过了,它不起作用。 “U”宏有一些问题。
来自https://github.com/Microsoft/cpprestsdk/wiki/FAQU macro的描述是:
The 'U' macro can be used to create a string literal of the platform type. If you are using a library causing conflicts with the 'U' macro, for example Boost.Iostreams it can be turned off by defining the macro '_TURN_OFF_PLATFORM_STRING' before including the C++ REST SDK header files.
如果我将光标指向U,则错误提示:
no operator "+" matches these operands operand types are; const wchar_t[57] + const std::string
我希望有人可以帮助我。谢谢。
【问题讨论】:
-
能否请您以某种方式指出您正在使用的
http_client类标题?我很想看到构造函数重载。 -
我认为我们可以使用 append 或 append_path? microsoft.github.io/cpprestsdk/classweb_1_1uri__builder.html
标签: c++ casablanca cpprest-sdk