nodejs實現HTTPS發起POST請求_node.js

來源:互聯網
上載者:User

準備用nodejs搞一個快速註冊163郵箱的東西,需要在某一步的時候post資料到https,node的官方文檔實在太簡陋了,網上找了個差不多的例子,拿來改了改用。

var util = require('util'),  https = require('https'); var regUrl = "https://ssl.mail.163.com/regall/unireg/call.do;jsessionid=%s?cmd=register.start&adapter=%s&reforward=common/reform&targetCmd=register.ctrlTop";var cookie = 'a=b;c=d;',mail = 'regUsername', pass = 'password', vcode='abcde';var _regUrl = util.format(regUrl, 'id123455', 'param2'); var post_option = url.parse(_regUrl); post_option.method = 'POST'; post_option.port = 443; var post_data = querystring.stringify({   'name' : mail,   'uid' : mail+'@163.com',   'confirmPassword' : pass,   'password' : pass,   'vcode' : vcode,   'flow' : 'main',   'from' : '163mail_right',   'mobile' : '',   }); post_option.headers = {   'Content-Type' : 'application/x-www-form-urlencoded',   'Content-Length' : post_data.length,   Cookie : cookie                        }; var post_req = https.request(post_option, function(res){    res.on('data', function(buffer){     console.log(buffer.toString());     }); post_req.write(post_data); post_req.end();

以上所述就是本文的全部內容了,希望大家能夠喜歡。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.