[英]PhantomJs, get query parameters when a POST request is sent
I'm using onResourceRequested
to listen for every resource requested. 我正在使用
onResourceRequested
来侦听请求的每个资源。 When the resource is request using GET method, I can get the query parameters from the url. 当使用GET方法请求资源时,我可以从url获取查询参数。
But when it is a POST request, how do I retrieve the parameters(such as form data) sent with the request? 但是,当它是POST请求时,如何检索与请求一起发送的参数(例如表单数据)?
The requestData
object has the following keys: headers
, id
, method
, time
, url
. requestData
对象具有以下键: headers
, id
, method
, time
, url
。
page.onResourceRequested = function (requestData, networkRequest) {
if(requestData.method == "POST")
console.log('Receive ' + JSON.stringify(requestData, undefined, 4));
};
Receive {
"headers": [
{
"name": "Origin",
"value": "https://mastec.taleo.net"
},
{
"name": "User-Agent",
"value": "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
},
{
"name": "Content-Type",
"value": "application/x-www-form-urlencoded"
},
{
"name": "Referer",
"value": "https://example.com?lang=en"
},
{
"name": "Accept",
"value": "*/*"
},
{
"name": "Content-Length",
"value": "20161"
}
],
"id": 18,
"method": "POST",
"time": "2015-07-16T14:03:54.838Z",
"url": "https://example3.com"
}
Generally, you can't. 通常,您不能。 PhantomJS doesn't expose a way to get the contents of any request.
PhantomJS没有公开获取任何请求内容的方法。
If you want to look into the request that is generated from an old-HTML (non-AJAX version) form submit, then you would need to scrape the form fields before submitting to get the contents. 如果要查看从旧HTML(非AJAX版本)表单提交生成的请求,则需要在提交之前先刮掉表单字段以获取内容。
If it is AJAXy, then there are three strategies that you can try. 如果是AJAXy,则可以尝试三种策略。 I've described them in my answer here .
我已经在我的回答中描述了它们。 The general solution would be to write an XHR object proxy.
通用解决方案是编写XHR对象代理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.