NodeJS没有通过cURL从PHP接收数据?

时间:2017-07-01 20:45:19

标签: php node.js curl

1。)试图让NodeJS从PHP获取$ content。我不知道出了什么问题。

2。)然后尝试将值发送回PHP(现在简化,但我会在发送之前对值进行一些操作。只是尝试让发送/接收过程正常工作)

PHP代码:

$url = 'http://123.456.789:8080/panel/';
$content = json_encode("your data to be sent");

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/json"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);

$json_response = curl_exec($curl);

$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

curl_close($curl);
$response = json_decode($json_response, true);

echo "<script>console.log( 'Debug Objects: " . $response . "' );</script>";

NodeJS代码:

router.post('/panel/', function(request, response){
    var myValue = request.body.data;
    console.log(myValue);
    response.send(myValue);
    response.end();
});

0 个答案:

没有答案