我使用的request
库来进行HTTP请求到服务器( https://github.com/request/request )。
Unfornatelly我得到了400的响应,因为一些数据在我的要求(可能饼干)丢失。
这是我正在做它:
let request = require('request');
request.post("https://some-server.com/asyncUserLogin", {
form: {
username: 'rapidtest',
password: 'rapidtest123',
TARGET_URL: targetUrl
},
jar: jar1
}, (err, res, body) => {
/*
* I am trying to get cookies from this request
* and pass it to the next in multiple ways,
* here I am stripping cookie manually,
* and trying to set Cookie: header
*/
let cookies = jar1.getCookies("https://some-server.com/asyncUserLogin");
let cookiesString: string = "";
cookies.forEach(cookie => {
if(cookiesString.length > 0)
cookiesString += ";"
cookiesString += cookie.key + "=" + cookie.value;
});
/*
* in this request I am trying to send POST to:
* https://some-server.com/getOauthCookie?grant_type=password_assertion&client_id=xxx-yyyy
* along with cookies retrieved in previous request,
* it should respone with 200 and some other cookies
*/
request.post("https://some-server.com/getOauthCookie", {
har: {
postData: {
mimeType: 'application/x-www-form-urlencoded',
params: [
{
name: 'grant_type',
value: 'password_assertion'
},
{
name: 'client_id',
value: 'xxx-yyyy'
}
]
},
headers: [
{
name: 'Content-Type',
value: 'application/x-www-form-urlencoded'
},
{
name: 'Cookies',
value: cookiesString
}
],
}
jar: jar1
}, (err, res, body) => {
//this request fails
});
});
我应该怎么做,可以肯定的,从第一个请求的cookie被传递到第二个?
我怎样才能显示它要求我做,到chceck如果缺少了什么/畸形( 如何查看请求从的node.js发送到服务器? )?