Node.js 无法从我的express应用程序中的curl请求获取数据?
我正在从laravel应用程序向express应用程序发送卷曲请求。当我触发curl请求时,它会出现在我的express应用程序中,但我无法从中获取任何数据。req.body为空。这是我从laravel应用程序发送的卷曲请求$数据包含对象数组Node.js 无法从我的express应用程序中的curl请求获取数据?,node.js,laravel,express,curl,Node.js,Laravel,Express,Curl,我正在从laravel应用程序向express应用程序发送卷曲请求。当我触发curl请求时,它会出现在我的express应用程序中,但我无法从中获取任何数据。req.body为空。这是我从laravel应用程序发送的卷曲请求$数据包含对象数组 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"http://some.com/event_upload_manager");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://some.com/event_upload_manager");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
在我的express应用程序中,代码如下所示
exports.event_uploader = function(req,res){
console.log("Curl Received");
console.log("Body : "+JSON.stringify(req.body));
console.log("Params : "+JSON.stringify(req.params));
console.log("Query : "+JSON.stringify(req.query));
}
我收到了Curl,然后是空请求。问题解决了,我刚刚将application/x-www-form-urlencoded作为头添加到我的Curl请求中,它来了,
此外,我在express app中添加了json解析器作为路由的中间件。您可以添加控制器方法而不仅仅是curl调用吗?不管怎样,为什么不使用本地curl呢?控制器方法是post-request,当它在另一个laravel应用程序中获取它时,它可以正常工作@是的,但是你的express应用程序得到了什么样的响应?
$server\u output
变量是通过return response()->json(['data'=>$server\u output])返回的代码>?Express设置中是否有中间件?