使用 cpprest 发送开机自检
Sending POST using cpprest
我有以下代码要发送 POST,但即使它编译正确,我也会收到错误
http_client client(U("http://l0.71.103.63:34568"));
json::value postData;
postData["name"] = json::value::string(U("Mohammad"));
http_response response = client.request(methods::POST,postData.to_string().c_str()).get();
if(response.status_code() == status_codes::OK)
{
auto body = response.extract_string();
std::wcout << L"Added new Id: " << body.get().c_str() << std::endl;
return std::stoi(body.get().c_str());
}
但是我在尝试运行程序时收到以下错误
terminate called after throwing an instance of 'web::uri_exception'
what(): provided uri is invalid: {"name":"Mohammad"}
Aborted (core dumped)
我认为
问题是您的IP地址。看起来您的 IP 地址有误?你有"http://l0.",其中">10"是">l0"(小写L(。
因此,网络:uri_exception。
你的请求是错误的(我确实认为(,应该看起来像这样:
auto response = client.request(methods::P OST, U("\"(, postData(.get((;
请求中的第二个参数是 URL 补码,您正在字符串中传递 json,因此会出现错误。
基本上你想要的语法是这样的:
pplx::task web::http::client::http_client::request ( const Method & MTD, const utility::string_t & path_query_fragment, const json::value & body_data, const pplx::cancellation_token & token = pplx::cancellation_token::none(( )
相关文章:
- 使用 cpprest (Casablanca) 返回 PDF 响应
- 带有日本字符的CPPREST?
- 如何使用 swagger-codegen cpprest 客户端库代码?
- LG电视通过串行使用Windows服务在PC开机后运行约30秒 - 如何更快地启动服务
- 如何在VS项目中静态链接没有dll文件的cpprest?
- 访问和存储/解析性std :: Chrono ::持续时间:: milliseconds(cpprest)时使用什么类型
- 使用CPPREST-SDK将STD ::向量转换为JSON
- 使用 cpprest 发送开机自检
- 使用 cpprest 通过 json 对象在 http post 中发送图像
- 响应代码 302 的 CPPREST 重定向位置
- 开机时自动登录
- 使用IE引擎下载页面+使用开机自检
- 无法通过 CHttpFile - C++/MFC 发送开机自检请求
- 从CPPRest库(即casablanca)获得的结果中提取基本STL字符串
- Microsoft Windows S通道SSPI自检
- 从cpprest lambda表达式访问自动变量
- 我想制作开机画面,现在我有两个问题
- CPPRest SDK向服务器发出HTTP请求