Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Use an HTTP client class to help send the requests. There are several available, but I have created one (<a href="https://github.com/broshizzledizzle/Http-Client" rel="nofollow">https://github.com/broshizzledizzle/Http-Client</a>) that I can give you help with.</p> <p><strong>Making a PUT request:</strong></p> <pre><code>&lt;?php require_once 'Http/Client.php'; require_once 'Http/Method.php'; require_once 'Http/PUT.php'; require_once 'Http/Request.php'; require_once 'Http/Response.php'; require_once 'Http/Uri.php'; use Http\Request; use Http\Response; header('Content-type:text/plain'); $client = new Http\Client(); //GET request echo $client-&gt;send( Request::create() -&gt;setMethod(new Http\PUT()) -&gt;setUri(new Http\Uri('http://localhost/linetime/user/1')) -&gt;setParameter('a', 'hello') )-&gt;getBody(); ?&gt; </code></pre> <p><strong>Processing a PUT request:</strong></p> <pre><code>//simply print out what was sent: switch($_SERVER['REQUEST_METHOD']) { case 'PUT': echo file_get_contents('php://input'); break; } </code></pre> <p><em>Note that I have an autoloader on my projects that will load all those includes for me, but you may want to consider making a file that will include everything if you don't want to go down that route.</em></p> <hr> <p><strong>Library-less:</strong></p> <pre><code>//initialization code goes here $requestBody = http_build_query( array('a'=&gt; 'hello'), '', '&amp;' ); $fh = fopen('php://memory', 'rw'); fwrite($fh, $requestBody); rewind($fh); curl_setopt($this-&gt;curl, CURLOPT_INFILE, $fh); curl_setopt($this-&gt;curl, CURLOPT_INFILESIZE, strlen($requestBody)); curl_setopt($this-&gt;curl, CURLOPT_PUT, true); //send request here fclose($fh); </code></pre> <p>Note that you use a stream to send the data.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload