我有https://api.gm-system.net/api/authenticate/searchStaffs/searchText
返回列表人员的 api。
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/FAQ的描述U 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
我希望有人能帮助我。谢谢。