doupao1978 2015-09-06 04:17
浏览 33

POST json返回400卷曲,但功能测试工作

I am trying to build the POST of an API using Symfony2 and FOSRestBundle. The following functional test returns OK.

 public function testPostArticleAction(){

        $this->client->request(
                'POST',
                '/api/v1/articles.json',
                array(),
                array(),
                array('CONTENT_TYPE' => 'application/json'),
                '{"articleContent":"The content of the content"}'
                );
        $response = $this->client->getResponse();

        $this->assertJsonResponse($response,201, false); 
    }

But when I try to send a request via Curl with the same request body, it gives me a 400 invalid json message:

{"code":400,"message":"Invalid json message received"}

Here are the curl commands I have tried:

curl -X POST -d '{"articleContent":"title1"}' http://localhost:8000/api/v1/articles --header "Content-type:application/json"

curl -X POST -d '{"articleContent":"title1"}' http://localhost:8000/api/v1/articles.json

Please to note that the GET returns to me a json like:

{"id":68,"article_content":"contents contents"}

But my field is articleContent in my doctrine mapping file. What am I missing? Your help is much appreciated.

  • 写回答

1条回答 默认 最新

  • dongxieting9623 2015-09-06 04:24
    关注

    Try updating your header option to:

    "Content-Type: application/json"
    

    Additionally - does this request require any type of authentication? You'd need to pass in an auth cookie if so.

    评论

报告相同问题?

悬赏问题

  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题