nodejs實(shí)現(xiàn)HTTPS發(fā)起POST請求
更新時間:2015年04月23日 10:50:44 投稿:hebedich
這篇文章主要介紹了nodejs實(shí)現(xiàn)HTTPS發(fā)起POST請求的實(shí)例代碼,非常的簡單實(shí)用,有需要的小伙伴可以參考下。
準(zhǔn)備用nodejs搞一個快速注冊163郵箱的東西,需要在某一步的時候post數(shù)據(jù)到https,node的官方文檔實(shí)在太簡陋了,網(wǎng)上找了個差不多的例子,拿來改了改用。
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();
以上所述就是本文的全部內(nèi)容了,希望大家能夠喜歡。
您可能感興趣的文章:
- nodejs處理http請求實(shí)例詳解之get和post
- Node.js中的HTTP?Server對象與GET、POST請求
- nodejs 使用http進(jìn)行post或get請求的實(shí)例(攜帶cookie)
- nodejs使用http模塊發(fā)送get與post請求的方法示例
- node.js+postman實(shí)現(xiàn)模擬HTTP服務(wù)器與客戶端交互
- 從零開始學(xué)習(xí)Node.js系列教程一:http get和post用法分析
- 輕松創(chuàng)建nodejs服務(wù)器(10):處理POST請求
- nodejs之get/post請求的幾種方式小結(jié)
- Node.js如何響應(yīng)Ajax的POST請求并且保存為JSON文件詳解
- NodeJS收發(fā)GET和POST請求的示例代碼
- Node發(fā)出HTTP POST請求的方法實(shí)例小結(jié)
相關(guān)文章
詳解基于Node.js的HTTP/2 Server實(shí)踐
HTTP/2目前已經(jīng)逐漸的在各大網(wǎng)站上開始使用,這篇文章主要介紹了詳解基于Node.js的HTTP/2 Server實(shí)踐,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-05-05xtemplate node.js 的使用方法實(shí)例解析
這篇文章主要介紹了xtemplate node.js 的使用方法實(shí)例說明,非常不錯,介紹的非常詳細(xì),具有參考借鑒價值,需要的朋友可以參考下2016-08-08修改Nodejs內(nèi)置的npm默認(rèn)配置路徑方法
今天小編就為大家分享一篇修改Nodejs內(nèi)置的npm默認(rèn)配置路徑方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-05-05nodejs 使用http進(jìn)行post或get請求的實(shí)例(攜帶cookie)
今天小編就為大家分享一篇nodejs 使用http進(jìn)行post或get請求的實(shí)例(攜帶cookie),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-01-01