如何使用 C++ 中的 cpprestsdk 发布 json 数据并从本地服务器获取响应
how to POST json data and get responses from the local server by using cpprestsdk in c++
谢谢你回答我的问题。
关于使用 cpprestsdk 的 c++ 中的 POST 请求。
我想将 json 数据发送到本地服务器,并使用 c++ 中的 cpprestsdk 通过 POST 从中获得响应。我做了一个程序,但它不起作用。我只能发送数据,但无法获取响应数据。 字符串 fomrat OK! 我可以相互转换字符串和 JSON 对象。
请帮助我。 我想这样做。
[伪源代码,如 C# 或 Java]
string POST(string postData){;
string receive = sendtoServer("http://localhost:8080/",postData);
return receive;
}
[Linux 或 window 命令 cURL]
curl -X POST http://localhost:8080/ -d '{"age":20,"sex":male"}'
#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <cpprest/http_client.h>
using namespace web;
using namespace web::http;
using namespace web::http::client;
auto POST(json::value postData){
http_client client(L"http://localhost:8080/");
auto receive = client.request(methods::POST, L"", postData.serialize(),
L"application/json").get().to_string().c_str();
printf("[DEBUG] receive = ");
std::wprintf(receive);
return receive;
}
建立成功,但它不起作用。 我不太了解并发::任务<>所以告诉我我的错误。 谢谢。enter code here
试试
http_client客户端(L("http://localhost:8080/"((;
自动接收 = client.request(methods::P OST, L("(, postData.serialize((,
L("application/json"((.get((.to_string((.c_str((;
而不是
http_client客户端(L"http://localhost:8080/"(;
自动接收 = client.request(methods::P OST, L", postData.serialize((,
L"application/json"(.get((.to_string((.c_str((;
请注意在"L"之后使用括号。
相关文章:
- NodeJs 服务器充斥着 UDP 广播,不发送响应
- 如何使用软化工具包从 OPC UA 服务器异步读取操作回调中的数据值响应中获取 NodeId 详细信息
- 将静态 IP 分配给我的 ESP32 服务器后不再响应
- 如何使用 C++ 中的 cpprestsdk 发布 json 数据并从本地服务器获取响应
- boost::asio http 服务器无法向 Postman 返回有效响应
- 提升野兽 服务器响应延迟 1 秒
- WebSocket服务器握手响应
- 服务器 API 不响应 Curl 函数
- FTP服务器试图登录时奇怪的响应
- 如何知道何时没有进一步的响应在使用SSL_READ()时从服务器接收
- 如何调用对带有句点的服务器的请求,并在响应无效时再次发送
- 服务器在实现 POST 请求时响应字符串不完整
- GET请求后服务器的响应不正确
- echo服务器没有响应udp
- 从服务器响应中解析 UTF8 字符串
- 服务器不使用 select(), cpp 响应新客户端
- 如何使用Poco C++从HTTP服务器响应中读取图像内容
- 将服务器响应(std::string)转换为png文件
- 谷歌服务器响应一个过时的html文件
- 将我的服务器响应char数组转换为wchar_t数组是处理客户端收到的服务器消息的正确方法吗?