http api请求有json body才解析

This commit is contained in:
xia-chu 2026-02-25 12:21:43 +08:00
parent 0ead9b6945
commit 725fdf1786

View File

@ -225,16 +225,18 @@ ApiArgsType getAllArgs(const Parser &parser) {
allArgs[pr.first] = strCoding::UrlDecodeComponent(pr.second); allArgs[pr.first] = strCoding::UrlDecodeComponent(pr.second);
} }
} else if (parser["Content-Type"].find("application/json") == 0) { } else if (parser["Content-Type"].find("application/json") == 0) {
try { if (!parser.content().empty()) {
stringstream ss(parser.content()); try {
Value jsonArgs; stringstream ss(parser.content());
ss >> jsonArgs; Value jsonArgs;
auto keys = jsonArgs.getMemberNames(); ss >> jsonArgs;
for (auto key = keys.begin(); key != keys.end(); ++key) { auto keys = jsonArgs.getMemberNames();
allArgs[*key] = jsonArgs[*key].asString(); for (auto key = keys.begin(); key != keys.end(); ++key) {
allArgs[*key] = jsonArgs[*key].asString();
}
} catch (std::exception &ex) {
WarnL << ex.what();
} }
} catch (std::exception &ex) {
WarnL << ex.what();
} }
} else if (!parser["Content-Type"].empty()) { } else if (!parser["Content-Type"].empty()) {
WarnL << "invalid Content-Type:" << parser["Content-Type"]; WarnL << "invalid Content-Type:" << parser["Content-Type"];