GET request
Implement the HTTPS request below, get the picture, and then turn to Base64 byte code
This. Checkcodeurl ='https://www.test.com/kaptcha.jsp';varHTTPS = require ('HTTPS'); https.Get( This. Checkcodeurl,function (res) {varDatas = []; varSize =0; Res.on ('Data', function (data) {Datas.push (data); Size+=data.length; }) Res.on ('End', function (data) {varBuff =Buffer.concat (datas, size); varPic = buff.tostring ('Base64'); Callback ({success:true, data:pic}); }). On ('Error', function (err) {Console.log ('Get Verification Code exception, exception reason'+err); Callback ({success:false, msg:'failed to get verification code'}); })
2 POST Request
I am here because the character returned is GBK, so the corresponding processing is done.
varHTTPS = require ('HTTPS');varIconv = require ('Iconv-lite');varQueryString = require ("QueryString");varReqdata ={str1:' One', str2:' A' } varPostData =querystring.stringify (reqdata); varopts ={method:'POST', Host:'www.test.com', Port:'443', Path:'/api/test', headers:{'Content-type':'application/x-www-form-urlencoded', 'Content-length':p Ostdata.length}} varreq =https.request (opts,function (res) {varDatas = []; varSize =0; Res.on ('Data', function (data) {Datas.push (data); Size+=data.length; }) Res.on ('End', function () {varBuff =Buffer.concat (datas, size); varstr = Iconv.decode (buff,'GBK'); Callback ({success:true, data:str}); })}) Req.on ('Error', function (err) {Console.log ('exception, cause of exception'+err); Callback ({success:false, msg:'failed'}); }) Req.write (postdata);
HTTPS Request in Node | Implement HTTPS requests, get pictures, then turn into Base64 bytecode