10. Web Services
Activity 10.1: Making Your Own POST Request to httpbin.org
Solution
- Create a
httpbin.phpfile in theguzzle-exampledirectory. Require the Composer autoload file and import theGuzzle Clientclass:<?php require 'vendor/autoload.php'; use GuzzleHttp\Client;
- Instantiate a new
Guzzle Clientby passing thehttpbinaddress:$client = new Client(['base_uri'=>'http://httpbin.org/']);
- Inside a
try…catchblock, make aPOSTrequest to the/response-headersendpoint. Add anAcceptheader set toapplication/jsonand set two query parameter key-value pairs, withfirstasJohnandlastasDoe:try {     $response=$client->request('POST', '/response-headers',[         'headers'=>[             'Accept'=>'application-json'     ...