javascript - 是否可以在 Java 或 JavaScript 中发出 HTTP (POST) 请求而无需等待响应
问题描述
我需要创建一个 http post 请求,而无需等待 Java 或 JavaScript 的响应。异步 http 调用不是我想要的,因为它仍在等待响应,只是在一个单独的线程上。
解决方案
是的,有可能,
我之前在使用 laravel 时已经完成了,我需要大量的 webhook 发送给商家。在我写登录等待响应之前,但它需要更多时间然后我谷歌并找到解决方案。这是示例。
function postCurlRequest(string $url, array $post_array, $check_ssl=true) {
// $url = 'https://post_url.com';
$cmd = "curl -L -X POST -H 'Content-Type: application/json'";
$cmd.= " -d '" . json_encode($post_array) . "' '" . $url . "'";
if (!$check_ssl){
$cmd.= "' --insecure"; // this can speed things up, though it's not secure
}
$cmd .= " > /dev/null 2>&1 &"; // don't wait for response
// echo $cmd;die;
exec($cmd, $output, $exit);
return $exit == 0;
}
推荐阅读
- bash - Turtle build:android 在 azuredevops 管道中失败,我错过了什么?
- excel - WeekNum VBA 函数不会在特定计算机上输出值
- javascript - google recaptcha api的硬编码域名强化问题
- kubernetes - Kubernetes liveness 探针是否与您的应用程序并行运行?
- c# - 将组合框绑定到枚举并将值传递回存储过程
- .net - 相同的 .NET dll 是否在不同机器上编译为相同的运行时汇编代码?
- javascript - 为什么地图没有出现?
- python - Python API 通过 SSH 执行远程命令
- java - Java Sockets:实时流式传输音频文件
- c# - C# 中带有 XML 标头的 CSV