php发送post请求到nodejs服务器,接受req.body为空?怎么办
$url = “http://120.0.0.1:5000/api/login”; // 参数数组 $data = [ “username”=>$username, “password”=>$password, ]; $ch = curl_init (); // 启动一个CURL会话 curl_setopt ( $ch, CURLOPT_URL, $url ); curl_setopt ( $ch, CURLOPT_POST, 1 ); curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data ); $result = curl_exec ( $ch ); // 执行操作 curl_close ( $ch ); // 关闭CURL会话 echo $result; 以上是php通过curl请求node
2 回复
将 curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
改为 curl_setopt ( $ch, CURLOPT_POSTFIELDS, http_build_query($data) );
@welefen 谢谢你啊,刚接curl,不太了解。