如何获取C++json帖子的json负载
How to get json payload for a C++ json post
我需要创建一个接受post数据的c++cgi应用程序。我将接受一个json对象。如何获取有效载荷?
我可以使用以下获取数据
int main() {
bool DEBUG = true;
cout << "content-type: text/html" << endl << endl;
//WHAT GOES HERE FOR POST
json=?????
//THIS IS A GET
query_string = getenv("QUERY_STRING");
}
如果方法类型为POST(您可能还想检查一下),则POST数据会写入stdin。因此,您可以使用这样的标准方法:
// Do not skip whitespace, more configuration may also be needed.
cin >> noskipws;
// Copy all data from cin, using iterators.
istream_iterator<char> begin(cin);
istream_iterator<char> end;
string json(begin, end);
// Use the JSON data somehow.
cout << "JSON was " << json << endl;
这将把cin中的所有数据读入json,直到EOF发生。
假设apache:
文档可在此处找到:
您会在底部附近找到它,但post数据是通过stdin提供的。
#include <iostream>
#include <string>
#include <sstream>
int main()
{
bool DEBUG = true;
std::cout << "content-type: text/htmlnn"; // prefer nn to std::endl
// you probably don't want to flush immediately.
std::stringstream post;
post << std::cin.rdbuf();
std::cout << "Got: " << post.str() << "n";
}
相关文章:
- 在c++中使用nlohmann从类到json的转换
- C++json插入数组
- nlohmann-json将一个数组插入到另一个数组中
- 如何使用curlpp通过POST方法上传文件和json数据
- JSON转换为nlohmann JSON-lib中的结构数组
- NLOHMANN 的 JSON 库将数组转换为结构向量
- 在nlohmann json中,如何将嵌套对象的数组转换为嵌套结构的向量
- 如何在 nlohmann 的 json 库中获取数组长度?
- UE4 C++ 我无法将 JSON 嵌套值获取到 TArray
- 如何在特定位置追加 json 文件
- 有没有办法让编译器在我放置字符串而不是 nlohmann::json 对象时抛出错误?
- 使用 jsoncpp 解析 json 数组字符串
- 具有内存顺序的原子负载存储
- 将 FlatBuffer 对象序列化为 JSON,而不使用其架构文件
- 如何使用英特尔 PIN 捕获阵列的所有负载?
- 如何在 c++ 非托管代码中反序列化 byte[] 的 json 字符串?
- 使用 cmake 生成 compile_commands.json
- 使用 curlpp 发布和接收 JSON 有效负载
- 使用 CPR 发送 nlohmann json 有效负载的最佳方法C++请求库
- 如何获取C++json帖子的json负载