gpt4 book ai didi

node.js - Node/表达 : How to POST to an external form with data?

转载 作者:搜寻专家 更新时间:2023-11-01 00:19:01 25 4
gpt4 key购买 nike

在使用要 POST 到表单的数据构造字符串后,如何使用 nodejs 和 expressjs 对另一个站点上的外部公共(public)表单执行 POST?

我无法为此找到一个简单的示例或文档,只能继续寻找如何在您自己的应用程序中处理和解析 POST 到表单。

最佳答案

Node.js 使这变得非常简单,并且在他们的官方文档中。

http://nodejs.org/api/http.html#http_http_request_options_callback

var options = {
host: 'www.google.com',
port: 80,
path: '/upload',
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();

关于node.js - Node/表达 : How to POST to an external form with data?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11327196/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com