Skip to content

Commit

Permalink
Updated HTTP chapter examples
Browse files Browse the repository at this point in the history
  • Loading branch information
lornajane committed Sep 13, 2015
1 parent 4d2df40 commit 2b223a4
Show file tree
Hide file tree
Showing 8 changed files with 269 additions and 23 deletions.
1 change: 1 addition & 0 deletions Chapter1-HTTP/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor/*
5 changes: 5 additions & 0 deletions Chapter1-HTTP/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require": {
"guzzlehttp/guzzle": "~6.0"
}
}
238 changes: 238 additions & 0 deletions Chapter1-HTTP/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions Chapter1-HTTP/guzzle-post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

require "vendor/autoload.php";

$url = "http://requestb.in/149njzd1";
//$url = "http://requestb.in/example";
$data = array("name" => "Lorna", "email" => "lorna@example.com");

$client = new \GuzzleHttp\Client();

$result = $client->post($url, ["json" => $data]);

echo $result->getBody();

7 changes: 4 additions & 3 deletions Chapter1-HTTP/php-curl-post.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?php

$url = "http://requestb.in/example";
$url = "http://requestb.in/149njzd1";
//$url = "http://requestb.in/example";
$data = array("name" => "Lorna", "email" => "lorna@example.com");

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));

curl_setopt($ch, CURLOPT_HTTPHEADER,
array('Content-Type: application/javascript')
array('Content-Type: application/json')
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);


var_dump($result);
4 changes: 2 additions & 2 deletions Chapter1-HTTP/php-curl.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

$url = "http://oreilly.com";
$url = "http://www.oreilly.com/";
$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);


var_dump($result);
14 changes: 0 additions & 14 deletions Chapter1-HTTP/php-pecl-http-post.php

This file was deleted.

9 changes: 5 additions & 4 deletions Chapter1-HTTP/php-streams-post.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?php

$url = "http://requestb.in/example";
$url = "http://requestb.in/149njzd1";
//$url = "http://requestb.in/example";
$data = array("name" => "Lorna", "email" => "lorna@example.com");

$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => array('Accept: application/javascript',
'Content-Type: application/x-www-form-urlencoded'),
'content' => http_build_query($data)
'header' => array('Accept: application/json',
'Content-Type: application/json'),
'content' => json_encode($data)
)
));

Expand Down

0 comments on commit 2b223a4

Please sign in to comment.