nodejs实现HTTPS发起POST请求
准备用nodejs搞一个快速注册163邮箱的东西,需要在某一步的时候post数据到https,node的官方文档实在太简陋了,网上找了个差不多的例子,拿来改了改用。
varutil=require('util'),
https=require('https');
varregUrl="https://ssl.mail.163.com/regall/unireg/call.do;jsessionid=%s?cmd=register.start&adapter=%s&reforward=common/reform&targetCmd=register.ctrlTop";
varcookie='a=b;c=d;',
mail='regUsername',pass='password',vcode='abcde';
var_regUrl=util.format(regUrl,'id123455','param2');
varpost_option=url.parse(_regUrl);
post_option.method='POST';
post_option.port=443;
varpost_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};
varpost_req=https.request(post_option,function(res){
res.on('data',function(buffer){
console.log(buffer.toString());
});
post_req.write(post_data);
post_req.end();
以上所述就是本文的全部内容了,希望大家能够喜欢。