Reputation: 53
so i have browser(netscape?) cookie like that nscookie or JSON cookie like jsoncookie
How should i pass this into request?
code source:
const
fs = require('fs'),
https = require('https'),
axios = require('axios');
function reqTest()
{
axios.default.request({
'url': 'google.com',
'method': 'post',
'headers':
{
'Cookie': 'cookie1=?; cookie2=?;'
}
}
).then(res => {
console.log(res);
})
}
Upvotes: 5
Views: 11992
Reputation: 316
Having the withCredentials
key enabled (set to 'true') should solve your issue.
Please try this:
const
fs = require('fs'),
https = require('https'),
axios = require('axios');
function reqTest()
{
axios.default.request({
'url': 'google.com',
'method': 'post',
'headers':
{
'Cookie': 'cookie1=?; cookie2=?;'
},
'withCredentials': 'true' // ADD THIS LINE
}
).then(res => {
console.log(res);
})
}
You can also enable this property for all requests in this instance of axios, changing axios' defaults:
axios.defaults.withCredentials = true;
axios.post(url, body).then(...).catch(...); // withCredentials is automatically enabled
Please report results.
Upvotes: 6