简体   繁体   中英

node js how to call webapi( x-www-form-urlencoded ) by sending data

I am trying to send data to a webservice , I put picture of how it goes from postman app.

I need to do it with node js, I could not found how to call webapi x-www-form-urlencoded.

Anyone help me ?

在此处输入图片说明

I used the npm package queryString and did something like this:

var formdata=queryString.stringify({
SOMEDATA: SOMEVALUE,
MOREDATA: MOREVALUE
});

var options={
hostname: <hostname>,
path: <path>
method: 'POST',
headers:{
'Content-Type':'application/x-www-form-urlencoded',
'Content-Length': formdata.length
}
}

let request = https.request(options,function(response){
//do something with the response data here
}
request.write(formdata);
request.end();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM