zoukankan      html  css  js  c++  java
  • 学习实践之DEMO《nodejs模拟POST登陆》

    一个简单的PHP接收参数页面
    <?php
        header("content-type:text/html;charset=utf-8");
        if($_POST[username] == "admin" && $_POST[password] == "123456") {
            echo "登陆成功";
        }else {
            echo "登陆失败";
        }
    ?>
    nodejs代码实现模拟登陆示例
    var http = require("http");
    var querystring = require("querystring"); 
    var contents = querystring.stringify({
        username: 'admin',
        password: '123456'
    });
    var options = {
        hostname: 'localhost',
        port: 9000,
        path: '/modules/login/checkSign.php',
        method: 'POST',
        headers:{
            "Content-Length":contents.length,
            "Content-Type":"application/x-www-form-urlencoded"
      } };

    var req = http.request(options, function(res) { res.setEncoding('utf8'); res.on('data', function (data) { console.log('BODY:' + data); }); }); req.on('error', function(e) { console.log('problem with request: ' + e.message); }); req.write(contents); req.end();
  • 相关阅读:
    js,js中使用正则表达式
    web开发中文件下载
    EL表达式
    Servlet Filter
    压缩文件 乱码问题(转载)
    MFC CopyDirectory
    SaveFileDialog
    Create Window
    CDateTimeCtrl 设置时间
    键值表
  • 原文地址:https://www.cnblogs.com/unofficial/p/4101298.html
Copyright © 2011-2022 走看看