飞盘。意想不到的令牌(当发送json的帖子时)

时间:2021-10-26 17:12:44

I'm getting the following error,

我得到了下面的错误,

 Error: Error parsing JSON string: Unexpected token <
    Given: <html>
<body>
<p>
  <b>400.</b> Invalid json request: numOfDays=1&amp;checkInDate=2013-04-10.
Make sure that key names and text values are quoted with "
</p>
</body>
</html>
Stacktrace:

using the following code:

使用下面的代码:

var frisby = require('frisby');

var天外飞仙=要求(“天外飞仙”);

  frisby.create('Ensure proper values in specified keys')
  .post('http://localhost:9090/bookRoom', {"numOfDays": 1 , "checkInDate":"2013-04-10"})
    .expectJSON({
        "checkInDate": "2013-04-10",
        "checkOutDate": "2013-04-11",
        "totalPrice": 130
    })
.toss()

I'm trying to pass this JSON - {"numOfDays": 1 , "checkInDate":"2013-04-10"}

我正在传递这个JSON - {"numOfDays": 1, "checkInDate":"2013-04-10"}

EDIT:

编辑:

It seems that the JSON being passed is in the following format. How do I get rid of those backslashes?

似乎正在传递的JSON是以下格式。我怎么才能摆脱那些反斜杠呢?

Handling booking request: "{\"numOfDays\":\"1\",\"checkInDate\":\"2013-04-10\"}"

2 个解决方案

#1


1  

Author of Frisby.js here. Please update to Frisby v0.8.5 - this is due to a change in the "request" module that Frisby depends on and uses.

天外飞仙的作者。js。请更新到Frisby v0.8.5——这是由于Frisby所依赖和使用的“请求”模块发生了变化。

#2


0  

I've just run into the same problem but I used different parameters for post. Precisely I added {json: true} as 3rd parameter and after a few minutes of struggling I removed it and it worked.

我刚刚遇到了同样的问题,但是我在post中使用了不同的参数。准确地说,我添加了{json: true}作为第3个参数,经过几分钟的努力,我删除了它,它成功了。

It looks your case might be the other way around. Try to put that 3rd parameter in the post method call and hope the best.

看起来你的情况正好相反。尝试将第三个参数放到post方法调用中,并希望得到最好的结果。

Related documentation: API docs

相关文档:API文档

#1


1  

Author of Frisby.js here. Please update to Frisby v0.8.5 - this is due to a change in the "request" module that Frisby depends on and uses.

天外飞仙的作者。js。请更新到Frisby v0.8.5——这是由于Frisby所依赖和使用的“请求”模块发生了变化。

#2


0  

I've just run into the same problem but I used different parameters for post. Precisely I added {json: true} as 3rd parameter and after a few minutes of struggling I removed it and it worked.

我刚刚遇到了同样的问题,但是我在post中使用了不同的参数。准确地说,我添加了{json: true}作为第3个参数,经过几分钟的努力,我删除了它,它成功了。

It looks your case might be the other way around. Try to put that 3rd parameter in the post method call and hope the best.

看起来你的情况正好相反。尝试将第三个参数放到post方法调用中,并希望得到最好的结果。

Related documentation: API docs

相关文档:API文档