[英]Why is the POST request response data null in CasperJS even though same request shows data in Postman
How do I resolve CasperJS script for POST request issue? 如何解决CasperJS脚本的POST请求问题? Get response data is null, even though same request show data in POSTMAN, with exact same request.
即使相同的请求在POSTMAN中显示数据,且请求完全相同,获取响应数据也为null。
casper = require('casper').create({
verbose : true
clientScripts : ['includes/jquery-2.1.1.min.js']
});
casper.start();
var productId = casper.cli.get("productId");
var pageNum = casper.cli.get("pageNum");
var url = 'https://example.com/store/getreviews?authuser=0';
var data= {
a:'val1',
b:'val2'
}; };
casper.thenOpen(
url,
{
method: 'POST',
data: data
}
);
casper.then(function(response) {
this.echo('Response: '+JSON.stringify(response,null,2));
this.capture('this.png');
});
casper.run();
Why is the POST request response data null in CasperJS
为什么CasperJS中的POST请求响应数据为空
PhantomJS doesn't provide the contents of any request or response. PhantomJS不提供任何请求或响应的内容。 You can only read the header information, the status code and the content length.
您只能读取标题信息,状态代码和内容长度。 You can access the request/response body in Slimer.js though.
不过,您可以在Slimer.js中访问请求/响应主体。
How do I resolve CasperJS script for POST request issue?
如何解决CasperJS脚本的POST请求问题?
Run using this command : casperjs --ssl-protocol=any example.js 使用以下命令运行:casperjs --ssl-protocol = any example.js
var casper = require('casper').create({
verbose : true,
logLevel :"debug"
});
casper.start();
casper.then(function() {
this.open('http://example.com/');
});
casper.then(function() {
resp = this.evaluate(function() {
var res = $.ajax({
url: 'https://example.com/store/getreviews?authuser=0',
method: 'POST',
data: {
a=val1,
b=val2
},
async: false
});
return res.responseText;
});
});
casper.then(function() {
console.log(resp);
});
casper.run();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.