在看NodeJS开发指南这本书时,书中的一个例子,讲解http.request的.代码如下:

 1 var http = require('http');
 2 var querystring = require('querystring');
 3 var contents = querystring.stringify({
 4 name: 'byvoid',
 5 email: 'byvoid@byvoid.com',
 6 address: 'Zijing 2#, Tsinghua University',
 7 });
 8 var options = {
 9 host: 'www.byvoid.com',
10 path: '/application/node/post.php',
11 method: 'POST',
12 headers: {
13 'Content-Type': 'application/x-www-form-urlencoded',
14 'Content-Length' : contents.length
15 }
16 };
17 var req = http.request(options, function(res) {
18 res.setEncoding('utf8');
19 res.on('data', function (data) {
20 console.log(data);
21 });
22 });
23 req.write(contents);
24 req.end();
View Code

相关文章:

  • 2021-11-07
  • 2021-10-09
  • 2022-01-08
  • 2021-04-11
  • 2021-06-27
  • 2021-12-30
  • 2021-11-02
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-23
  • 2021-12-17
  • 2021-06-30
  • 2022-12-23
相关资源
相似解决方案