简体   繁体   English

为什么即使同一请求在Postman中显示数据,CasperJS中的POST请求响应数据为何也为空

[英]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请求问题?

Here are some workarounds. 是一些解决方法。

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.

相关问题 为什么在 Postman 中我的帖子请求可以工作,但即使我也在做同样的事情,但在浏览器中却不行? - How come in Postman my post request works but not in the browser even though I'm doing the same? 为什么即使在 Postman 中返回,我也无法从 POST 请求中接收正文? - Why can't I receive the body from a POST request even though it is returned in Postman? 为什么即使它适用于 Postman,它也不能成功发布我的数据? - Why won't it POST my data successfully even though it works on Postman? 即使在同一函数中的var_dump显示数据,帖子也无法在PHP函数中工作 - Post not working in PHP function, even though var_dump in same function shows the data 为什么相同的POST请求在POSTMAN中起作用,但在浏览器AJAX中却不起作用(找不到404)? - Why the same POST request works in POSTMAN but not in browser AJAX (404 Not Found)? 多个Post请求CasperJS - Multiple Post request CasperJS 即使PHP返回正确的数据,jQuery .post也没有响应 - No response from jQuery .post even though PHP is returning correct data 如何将GET响应数据传递到POST请求 - How to pass GET response data to POST Request Axios 发布请求不发送数据或接收响应 - Axios post request not sending data or recieving response 角度发布请求未显示任何响应数据 - Angular post request not showing any response data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM