相关疑难解决方法(0)

Node.js Express中的HTTP GET请求

如何从node/express中发出HTTP请求?我需要连接到另一个服务.我希望该调用是异步的,并且回调包含远程服务器响应.

javascript httprequest node.js express

182
推荐指数
6
解决办法
42万
查看次数

在Node.JS上使用请求模块POST数据

该模块是'请求https://github.com/mikeal/request

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

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

在另一端我有

echo $_POST['mes'];
Run Code Online (Sandbox Code Playgroud)

我知道php没有错...

request node.js

125
推荐指数
6
解决办法
28万
查看次数

在Chrome调试器中看不到HTTP POST有效负载?

我已经检查了这个那个.但是,我的调试器如下所示.

失败的例子

没有表单数据,没有原始内容.

没有表单数据,没有原始内容

原始示例(*虽然路径与屏幕捕获不同,但它们都无法读取发布数据)

POST https://192.168.0.7/cgi-bin/icul/;stok=554652ca111799826a1fbdafba9d3ac1/remote_command HTTP/1.1
Host: 192.168.0.7
Connection: keep-alive
Content-Length: 419
accept: application/json, text/javascript, */*; q=0.01
Origin: https://192.168.0.7
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36
content-type: application/x-www-form-urlencoded; charset=UTF-8
Referer: https://192.168.0.7/cgi-bin/icul/;stok=554652ca111799826a1fbdafba9d3ac1/smartmomentl/access-point/network
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8,zh-TW;q=0.6,zh;q=0.4
Cookie: sysauth=f15eff5e9ebb8f152e163f8bc00505c6

command=import&args=%7B%22--json%22%3Atrue%2C%22--force%22%3Atrue%2C%22--mocks%22%3A%22%7B%5C%22DEL%5C%22%3A%7B%7D%2C%5C%22SET%5C%22%3A%7B%5C%22dhcp%5C%22%3A%7B%5C%22lan%5C%22%3A%7B%5C%22.section%5C%22%3A%5C%22dhcp%5C%22%2C%5C%22interface%5C%22%3A%5C%22lan%5C%22%2C%5C%22ignore%5C%22%3A%5C%220%5C%22%2C%5C%22leasetime%5C%22%3A%5C%2212h%5C%22%2C%5C%22range%5C%22%3A%5C%22172.16.0.100-172.16.0.200%5C%22%7D%7D%7D%7D%22%7D

HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Status: 200 OK
Content-Type: text/html; charset=utf-8
Cache-Control: no-cache
Expires: 0
Transfer-Encoding: chunked
Date: Thu, 01 Jan 1970 00:09:27 GMT
Server: lighttpd/1.4.30

31
{ "ctx": "No …
Run Code Online (Sandbox Code Playgroud)

post google-chrome http-post google-chrome-devtools

65
推荐指数
4
解决办法
3万
查看次数

通过POST请求从node.js服务器向node.js服务器发送数据

我正在尝试通过POST从node.js服务器到另一个node.js服务器的请求发送数据.我在"client"node.js中所做的如下:

var options = {
    host: 'my.url',
    port: 80,
    path: '/login',
    method: 'POST'
};

var req = http.request(options, function(res){
    console.log('status: ' + res.statusCode);
    console.log('headers: ' + JSON.stringify(res.headers));
    res.setEncoding('utf8');
    res.on('data', function(chunk){
        console.log("body: " + chunk);
    });
});

req.on('error', function(e) {
    console.log('problem with request: ' + e.message);
});

// write data to request body
req.write('data\n');
req.write('data\n');
req.end();
Run Code Online (Sandbox Code Playgroud)

这个块或多或少来自node.js网站,所以它应该是正确的.我唯一没看到的是如何在options变量中包含用户名和密码来实际登录.这就是我如何处理服务器node.js中的数据(我使用express):

app.post('/login', function(req, res){
    var user = {};
    user.username = req.body.username;
    user.password = req.body.password;
        ...
});
Run Code Online (Sandbox Code Playgroud)

如何将这些usernamepassword字段添加到 …

node.js

51
推荐指数
2
解决办法
15万
查看次数

如何在node.js中处理POST请求

我正在尝试处理发送到我的node.js服务器的post请求.名为server.js的JavaScript文件在浏览器上显示一个表单.我希望在将表单值发布到node.js后端后访问它们.

表单包含用户名,存储库和分支.提交表单时,我想将此数据显示回用户.

server.js代码:

var http = require('http');

http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/html'});
response.end('<html><body>'
    + '<h1>XYZ Repository Commit Monitor</h1>'
    + '<form method="post" action="." enctype="application/x-www-form-urlencoded"><fieldset>'
    + '<div><label for="UserName">User Name:</label><input type="text" id="UserName" name="UserName" /></div>'
    + '<div><label for="Repository">Repository:</label><input type="text" id="Repository" name="Repository" /></div>'
    + '<div><label for="Branch">Branch:</label><input type="text" id="Branch" name="Branch" value="master" /></div>'
    + '<div><input id="ListCommits" type="submit" value="List Commits" /></div>'
    + '</fieldset></form>'
    + '</body></html>');
}).listen(8124);

console.log('Server running at http://127.0.0.1:8124/');
Run Code Online (Sandbox Code Playgroud)

javascript html5 javascript-events node.js

45
推荐指数
1
解决办法
6万
查看次数

如何在没有任何第三方模块的Node Js中发布https帖子?

我正在开发一个需要https get和post方法的项目.我在这里有一个简短的https.get函数...

const https = require("https");

function get(url, callback) {
    "use-strict";
    https.get(url, function (result) {
        var dataQueue = "";    
        result.on("data", function (dataBuffer) {
            dataQueue += dataBuffer;
        });
        result.on("end", function () {
            callback(dataQueue);
        });
    });
}

get("https://example.com/method", function (data) {
    // do something with data
});
Run Code Online (Sandbox Code Playgroud)

我的问题是没有https.post,我已经在这里用https模块尝试了http解决方案如何在node.js中发出HTTP POST请求?但返回控制台错误.

我在浏览器中使用Ajax和Ajax发布到同一个api时没有问题.我可以使用https.get来发送查询信息,但我认为这不是正确的方法,如果我决定扩展,我认为它不会在以后发送文件.

是否有一个小的例子,有最低要求,使https.request成为https.post,如果有的话?我不想使用npm模块.

https post node.js

42
推荐指数
4
解决办法
6万
查看次数

将https请求发送到Node js中的休息服务的步骤

将节点js中的https请求发送到休息服务的步骤是什么?我有一个api暴露像https://133-70-97-54-43.sample.com/feedSample/Query_Status_View/Query_Status/Output1?STATUS=Joined%20school

如何传递请求以及我需要为此API提供哪些选项,如主机,端口,路径和方法?

rest node.js

28
推荐指数
4
解决办法
10万
查看次数

如何从node.js Express发送POST请求?

有人能告诉我从node.js Express发送post请求的最简单方法,包括如何传递和检索一些数据?我希望在PHP中类似于cURL.

javascript post http node.js express

27
推荐指数
4
解决办法
8万
查看次数

Node.js HTTPS POST请求标头

我想使用Node.js将状态更新发布到Facebook组.似乎Node.js没有发送标题......

var https = require('https');

var options = {
    host: 'graph.facebook.com',
    port: 443,
    path: '/'+group_id+'/feed?access_token='+access_token,
    method: 'POST',
    headers: { 'message': text }
};

var req = https.request(options, function(res) {
    console.log("statusCode: ", res.statusCode);
    console.log("headers: ", res.headers);

    res.on('data', function(d) {
        process.stdout.write(d);
    });
});

req.end();
Run Code Online (Sandbox Code Playgroud)

这是日志数据:

statusCode:  400
headers:  { 'cache-control': 'no-store',
  'content-type': 'text/javascript; charset=UTF-8',
  expires: 'Sat, 01 Jan 2000 00:00:00 GMT',
  p3p: 'CP="Facebook does not have a P3P policy. Learn why here: http://fb.me/p3p"',
  pragma: 'no-cache',
  'www-authenticate': 'OAuth "Facebook Platform" "invalid_request" "(#100) A …
Run Code Online (Sandbox Code Playgroud)

facebook node.js

18
推荐指数
1
解决办法
6万
查看次数

带有Node.js的HTTP PUT请求

我正在试图弄清楚如何使用node.js发出HTTP PUT请求.我尝试了很多不同的东西,但无法让它发挥作用.

想法是有一个放置文件的方法,例如:

function putFile(file_path, callback) {
    // Put the file
}
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激.

node.js

13
推荐指数
1
解决办法
5万
查看次数