Skip to content

Instantly share code, notes, and snippets.

@xeecos
Last active June 24, 2025 14:30
Show Gist options
  • Select an option

  • Save xeecos/297ee33ac1d0b7ac4d889a3c21155b18 to your computer and use it in GitHub Desktop.

Select an option

Save xeecos/297ee33ac1d0b7ac4d889a3c21155b18 to your computer and use it in GitHub Desktop.
req json param
svr.Post("/task", [](const Request &req, Response &res)
{
struct Task task;
json info;
int action = 0;
if(req.has_param("action"))
{
action = atoi(req.get_param_value("action").c_str());
}
if(req.has_file("task"))
{
json paramsJson = json::parse(req.get_file_value("task").content.c_str());
task.interval = paramsJson["interval"].get<float>();
task.exposure = paramsJson["exposure"].get<float>();
task.fps = paramsJson["fps"].get<float>();
task.count = paramsJson["count"].get<float>();
info["res"] = "done";
}
else if(action == 1)
{
}
else if(action == 2)
{
}
res.set_content(info.dump(), "application/json");
});
let xhr = new XMLHttpRequest();
let form = new FormData();
let jsonBlob = new Blob([JSON.stringify({
interval: 10,
exposure: 1,
fps:25,
count:1000
})], {type: 'application/json'});
form.append('task', jsonBlob, "task.json");
xhr.open('POST',`/task`, true);
xhr.onreadystatechange = async function() {//Call a function when the state changes.
if(xhr.readyState == 4 && xhr.status == 200) {
}
}
xhr.send(form);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment