最近2018中文字幕在日韩欧美国产成人片_国产日韩精品一区二区在线_在线观看成年美女黄网色视频_国产精品一区三区五区_国产精彩刺激乱对白_看黄色黄大色黄片免费_人人超碰自拍cao_国产高清av在线_亚洲精品电影av_日韩美女尤物视频网站

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
nodejs使用http模塊發(fā)送get與post請求的方法示例

本文實例講述了nodejs使用http模塊發(fā)送get與post請求的方法。分享給大家供大家參考,具體如下:

10年積累的成都網(wǎng)站設計、成都網(wǎng)站制作經(jīng)驗,可以快速應對客戶對網(wǎng)站的新想法和需求。提供各種問題對應的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡服務。我雖然不認識你,你也不認識我。但先網(wǎng)站設計后付款的網(wǎng)站建設流程,更有西烏珠穆沁免費網(wǎng)站建設讓你可以放心的選擇與我們合作。

GET請求

var http = require('http');
var querystring = require('querystring');
var data = {
  a: 123,
  time: new Date().getTime()};//這是需要提交的數(shù)據(jù)
var content = querystring.stringify(data);
var options = {
  hostname: '127.0.0.1',
  port: 3000,
  path: '/pay/pay_callback?' + content,
  method: 'GET'
};
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);
});
req.end();

POST請求

var http = require('http');
var querystring = require('querystring');
var post_data = {
  a: 123,
  time: new Date().getTime()};//這是需要提交的數(shù)據(jù)
var content = querystring.stringify(post_data);
var options = {
  hostname: '127.0.0.1',
  port: 3000,
  path: '/pay/pay_callback',
  method: 'POST',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  }
};
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);
  //JSON.parse(chunk)
  });
});
req.on('error', function (e) {
  console.log('problem with request: ' + e.message);
});
// write data to request body
req.write(content);
req.end();

希望本文所述對大家nodejs程序設計有所幫助。


網(wǎng)站欄目:nodejs使用http模塊發(fā)送get與post請求的方法示例
URL地址:http://fisionsoft.com.cn/article/jgsdig.html