Home > Web Front-end > JS Tutorial > nodejs implements HTTPS to initiate POST request_node.js

nodejs implements HTTPS to initiate POST request_node.js

WBOY
Release: 2016-05-16 16:02:40
Original
3659 people have browsed it

I am going to use nodejs to create something that can quickly register 163 mailboxes. I need to post data to https at a certain step. The official documentation of node is too simple. I found a similar example online and modified it.

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();
Copy after login

The above is the entire content of this article, I hope you all like it.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template