- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 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
。
我怎样才能让它接受任何像这样的搜索文本。
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
希望有人能帮帮我。谢谢。
最佳答案
自
The C++ REST SDK uses a different string type dependent on the platform being targeted. For example for the Windows platforms utility::string_t is std::wstring using UTF-16, on Linux std::string using UTF-8.
你应该使用 utility::string_t
需要时上课,不要将其与 std::string
混用或 const char *
(并在需要文字时使用 U
宏)。
换句话说,你的函数应该接受 utility::string_t
作为其 searchText
参数(而不是 std::string
):
void MyTest(utility::string_t searchText)
{
http_client client(U("https://api.gm-system.net/api/authenticate/searchStaffs/") + searchText);
// etc ...
}
像这样使用它:
int main()
{
utility::string_t searchText = U("Michael");
MyTest(searchText);
return 0;
}
如果必须从特定于平台的上下文中调用该函数,则相应的 std
type 可以用作传入的参数类型(即在 Windows 上使用 std::wstring
):
std::wstring searchText = L"Michael";
MyTest(searchText);
关于c++ - cpprestsdk/casablanca 的 http_client,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49868625/
我有一个 api https://api.gm-system.net/api/authenticate/searchStaffs/searchText,它返回一个员工列表。 这里是我使用 cppres
我正在尝试使用 casablanca 'c++ rest sdk' 为 REST 请求运行 c++ Windows 应用程序。我创建了新的“CLR 空项目”(visual studio 2012)并添
我正在尝试使用 Http_Client.Convenience 模块编译一个文件(他的文档在这里:Http_Client.Convenience 我有文件 foo.ml : let result =
我正在尝试使用 Http_client.Convenience.http_post制作 http post request . API 相当简单: val http_post : string ->
我正在我的 ubuntu 8.04 开发服务器上设置 wso2 php Web 服务框架。 但是我的网络服务失败了。查看 wsf_client.log (框架的自定义日志)文件给了我问题中的错误。 我
我想向网络服务发出请求,获取 XML 内容,然后解析它以获取服务返回的特定值。 代码将使用原生 C++11 (MS Visual Studio 2013) 编写。 Cassablanca选择了 PPL
我正在尝试使用 django rest 框架创建一个简单的 API。在 View 中,我有以下代码。 from django.shortcuts import render from movi
我正在尝试使用 C++ REST SDK (Casablanca) 库执行 POST HTTP 请求,但我没有成功……我也找不到任何最近的/工作片段。谁能帮帮我? 通过我的以下代码,我获得了一个运行时
我是一名优秀的程序员,十分优秀!