无法从我的快递应用程序中的curl请求中获取数据?

问题描述 投票:0回答:1

我正在发送一个laravel应用程序的curl请求来表达应用程序。当我触发curl请求然后它来到我的快递应用程序但我无法从中获取任何数据。 req.body是空的。这是我从laravel应用程序发送的卷曲请求。 $ data包含对象数组。

                    $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);

在我的快递应用中,代码就像这样

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 Received然后空的请求。

node.js laravel express curl
1个回答
0
投票

问题解决了,我只是将application / x-www-form-urlencoded作为标题添加到我的curl请求中它来了,除此之外我还在快递应用中添加了json解析器作为我的路由的中间件。

© www.soinside.com 2019 - 2024. All rights reserved.