CasperJS sends empty POST data to endpoint

故事扮演 提交于 2019-12-02 08:14:26

Yes, at the time of calling thenOpen the productDetails variable is still undefined. You can just split the thenOpen call into then and open so that it is defined when open is actually called.

self.then(function(){
    this.open('http://localhost.endpoint.lan/saveScrapingData.php', {
        method:'post',
        data: {
            name:'Alan',
            info: productDetails
        },
        headers: {
            'Content-type': 'application/x-www-form-urlencoded'
        }
    });
});

This is because of the asynchronous manner of casper steps (then* or wait*). They are scheduled but executed later. The problem is that by calling thenOpen with the settings object fixes the value of productDetails to undefined since the the previous step was not yet executed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!