尝试重新创建网站上的表单提交的发布请求,但是当我直接使用节点模块请求重新创建请求时,我得到302状态代码,并且正文为空。我将附上我要重新创建的帖子请求和我所拥有的代码的图片(我将Cookie保留在cookie罐中,并事先发出适当的请求以存储登录cookie等)。谢谢!
const request = requests.defaults({
jar: true
})
const fetchGradesData = {
'f': 'f',
'javax.faces.ViewState': 'j_id5',
'f:inside:GradedTab:AssignMPSel': '4',
'f:inside:GradedTab:j_id_jsp_394614891_10pc8': '03-16-2019',
'f:inside:GradedTab:j_id_jsp_394614891_12pc8': '06-07-2019',
'f:_idcl': 'f:inside:j_id_jsp_1774471256_10pc5'
}
const fetchGradesHeaders = {
'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.9",
'Connection': "keep-alive",
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36",
}
request.post(
"https://mybackpack.gulliverschools.org/SeniorApps/studentParent/academic/dailyAssignments/gradeBookGrades.faces", {
headers: fetchGradesHeaders,
formData: fetchGradesData
},
function (err, response, body) {
console.log(response.statusCode)
}
)
这是我用来发送帖子请求的代码。
下面是我得到的响应标头以及chrome开发工具中的响应标头:
{ date: 'Mon, 01 Apr 2019 17:29:19 GMT',
server: 'Apache',
'x-frame-options': 'SAMEORIGIN',
'x-xss-protection': '1;mode=block',
'strict-transport-security': 'max-age=31536000; includeSubDomains',
'content-security-policy': 'default-src \'self\' mybackpack.gulliverschools.org:444 *.senior-systems.com:444 *.google-analytics.com ; script-src \'self\' mybackpack.gulliverschools.org:444 *.senior-systems.com:444 seal.godaddy.com \'unsafe-inline\' \'unsafe-eval\' *.google-analytics.com; style-src \'self\' mybackpack.gulliverschools.org:444 *.senior-systems.com:444 \'unsafe-inline\'; img-src \'self\' mybackpack.gulliverschools.org:444 *.senior-systems.com:444 data: *.google-analytics.com seal.godaddy.com *.seniormbp.com ; object-src \'self\' mybackpack.gulliverschools.org:444 *.senior-systems.com:444 *.google-analytics.com *.seniormbp.com \'unsafe-inline\'; child-src \'self\' mybackpack.gulliverschools.org:444 *.senior-systems.com:444; frame-ancestors \'self\' *.senior-systems:444 *.goradius.com;',
p3p: 'CP=\'CAO PSA OUR\'',
'cache-control': 'no-store',
expires: 'Mon, 01 Apr 2019 17:27:39 GMT',
'x-powered-by': 'JSF/1.2',
'set-cookie': [ 'senior.session.expired=true' ],
location: 'https://mybackpack.gulliverschools.org/SeniorApps/studentParent/academic/dailyAssignments/gradeBookGrades.faces?convid=20816',
'content-length': '0',
'keep-alive': 'timeout=5, max=100',
connection: 'Keep-Alive' }
答案 0 :(得分:0)
根据MDN Documentation,响应代码302 为:
找到的超文本传输协议(HTTP)302重定向状态响应代码表示所请求的资源已被临时移动到位置标头给出的URL。浏览器重定向到此页面,但是搜索引擎不会更新其到资源的链接(在“ SEO说”中,据说“ link-juice”没有发送到新的URL)。
因此,我建议您考虑这种情况,该情况是资源在该 url 中不可用时出现的。
一种实现方法是询问响应代码,如果是302,则重复请求,但重复到位置响应标头中的链接。