POST request with JSON body

后端 未结 5 1438
渐次进展
渐次进展 2020-11-28 20:27

I would like to add a post to a Blogger blog via PHP. Google provided the example below. How to use that with PHP?

You can add a post for a blog by se

5条回答
  •  一向
    一向 (楼主)
    2020-11-28 21:04

    I made API sending data via form on website to prosperworks based on @Rocket Hazmat, @dbau and @maraca code. I hope, it will help somebody:

     $name,
                                'email' => array('email' => $email)
                            );
    
        //sending request (according to prosperworks documentation):
        // use key 'http' even if you send the request to https://...
        $options = array(
            'http' => array(
                'header'  => "Content-Type: application/json\r\n".
                 "X-PW-AccessToken: YOUR_TOKEN_HERE\r\n".
                 "X-PW-Application:developer_api\r\n".
                 "X-PW-UserEmail: YOUR_EMAIL_HERE\r\n",
                'method'  => 'POST',
                'content' => json_encode($data)
            )
        );
    
        //engine:
        $context  = stream_context_create($options);
        $result = file_get_contents($url, false, $context);
        if ($result === FALSE) { /* Handle error */ }
        //compiling to JSON (as wrote above):
        $resultData = json_decode($result, TRUE);
        //display what was sent:
        echo '

    Sent:

    '; echo $resultData['published']; //dump var: var_dump($result); } ?>

    Name:
    Email:

提交回复
热议问题