开发者

How do I send a request body with a post in my symfony functional test?

How do you send a request body with a post? I need to post a json document in my functional开发者_JAVA百科 test.. symfony 1.4


This is what I used recently, I found it on a blog post, which I don't recall.

    $post=array(
        "a"=>"one",
        "b"=>"two",
        "c"=>"three"
    );


    $values = json_encode($post);

    $session = curl_init($request);
    curl_setopt($session, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    curl_setopt ($session, CURLOPT_POST,1);
    curl_setopt ($session, CURLOPT_POSTFIELDS, $values);

    // Tell curl not to return headers, but do return the response
    curl_setopt($session, CURLOPT_HEADER, false);
    curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

    $response = curl_exec($session);
    curl_close($session);

    return json_decode($response);

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜