在 Node.JS 上使用请求模块 POST 数据 [英] POST data with request module on Node.JS

查看:21
本文介绍了在 Node.JS 上使用请求模块 POST 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个模块是'request https://github.com/mikeal/request

This module is 'request https://github.com/mikeal/request

我想我正在遵循每一步,但我错过了一个论点..

I think i'm following every step but i'm missing an argument..

var request = require('request');
request.post({
        url: 'http://localhost/test2.php',
         body: "mes=heydude"
         }, function(error, response, body){
            console.log(body);
    });

另一端我有

echo $_POST['mes'];

而且我知道 php 没有错...

And i know the php isn't wrong...

推荐答案

您应该查看 .它为您执行此操作并支持多部分数据等等.

You should check out Needle. It does this for you and supports multipart data, and a lot more.

我发现我缺少一个标题

var request = require('request');
request.post({
  headers: {'content-type' : 'application/x-www-form-urlencoded'},
  url:     'http://localhost/test2.php',
  body:    "mes=heydude"
}, function(error, response, body){
  console.log(body);
});

这篇关于在 Node.JS 上使用请求模块 POST 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆