[英]Phantomjs script stops execution after json object parsing
I'm trying to pass post data to the following phantomjs script (using php/curl): 我正在尝试将发布数据传递到以下phantomjs脚本(使用php / curl):
server.listen(port, function(request, response) {
// Print some information Just for debug
console.log("request method: ", request.method); // request.method POST or GET
if(request.method == 'POST' ){
console.log("POST params should be next: ");
console.log(request.headers);
code = response.statusCode = 200;
response.write(code);
console.log("POST params: ",request.postRaw);
console.log("POST params: ",JSON.stringify(request.postRaw));
var json = request.postRaw;
obj = JSON.parse(json);
console.log(obj.email);
console.log(obj.pass);
var userName = json.stringify(obj.email);
var userPass = json.stringify(obj.pass);
console.log("I'm here");
I am trying to parse out the username and password from the post request. 我正在尝试从发布请求中解析出用户名和密码。 I notice that if I leave in:
我注意到如果我离开:
var userName = json.stringify(obj.email);
var userPass = json.stringify(obj.pass);
the script will hang after: 该脚本将在以下情况后挂起:
console.log("I'm here");
If I remove these 2 lines the entire script will execute normally. 如果删除这两行,则整个脚本将正常执行。 Why is this happening?
为什么会这样呢? How can I fix this so I can parse the json object (obj), but the script will not hang?
如何解决此问题,以便可以解析json对象(obj),但脚本不会挂起?
In regular javascript, JSON is capitalized (and case-sensitive). 在常规javascript中, JSON大写(且区分大小写)。 Not sure how PhantomJS' subset of javascript lines up with regular javascript, but it'd be my guess that you should probably use capital-case JSON there too.
不知道PhantomJS的javascript子集如何与常规javascript对齐,但是我猜测您也应该在那里使用大写字母JSON。
So for example: 因此,例如:
JSON.stringify(obj.email);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.