Nodejs连接PHP,Nodejs传数据到PHP

版权声明:本文为博主原创文章,未经博主允许不得转载 https://blog.csdn.net/qq983392709/article/details/84874685

nodejs做服务器时,有时需要将数据传递给PHP进行后处理,则了解此模块有利于增加开发效率

nodejs文件

var express = require('express');
var request = require('request');

var app = express();

request.post(
    {
        url:'http://127.0.0.1:8000/test.php',
        form:{
            'fileName':'master'
        },
        function (err, httpRes, body) {
            if(err){
                return console.error('upload failed:',err)
            }
            console.log('upload successful! Server responded with:',body)
        }
    }
);

app.listen(3000,'127.0.0.1',function(){
    console.log('server is started');
});

test.php文件

<?php
    $fileName = $_POST['fileName']; 
    echo($fileName)
?>

此过程只是一个简单连接,PHP内部可自由完善

原文连接https://blog.csdn.net/qq983392709/article/details/84874685

猜你喜欢

转载自blog.csdn.net/qq983392709/article/details/84874685