亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用nodejs http API模擬web form表單提交?

如何使用nodejs http API模擬web form表單提交?

守候你守候我 2019-04-19 16:12:31
現在一個應用需要訪問不同域下的TAM安全認證服務,需要模擬form表單提交到WebSEAL,先謝謝了。以下是我目前嘗試的http請求寫法:varhttp=require('http');varquerystring=require('querystring');varpost_options={host:'192.168.1.22',port:'80',path:'/pkmslogin.form',method:'post',auth:'username:123456','login-form-type':'pwd',headers:{'Content-Type':'application/x-www-form-urlencoded'}};varpost_data=querystring.stringify({username:'username',password:'123456','login-form-type':'pwd'});//Setuptherequestvarpost_req=http.request(post_options,function(res){res.setEncoding('utf8');console.log(JSON.stringify(res.headers));res.on('data',function(chunk){console.log('Response:'+chunk);});});console.log(JSON.stringify(post_req.headers));//postthedata//post_req.write(post_data);post_req.end();
查看完整描述

2 回答

?
阿晨1998

TA貢獻2037條經驗 獲得超6個贊

還需注意以下兩點:
//1、在頭中設置好內容長度
headers:{
'Content-length':post_data.length,
'Content-Type':'application/x-www-form-urlencoded'
}
varpost_data=querystring.stringify({
username:'username',
password:'123456',
'login-form-type':'pwd'
});
//2、參數寫入到流中
post_req.write(post_data);
                            
查看完整回答
反對 回復 2019-04-19
  • 2 回答
  • 0 關注
  • 364 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號