Skip to content

Commit

Permalink
feature: post data with formdata
Browse files Browse the repository at this point in the history
closes #99
  • Loading branch information
g105b committed Jul 3, 2023
1 parent 6a0aa42 commit a9b8e10
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions example/02-post-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require(implode(DIRECTORY_SEPARATOR, ["..", "vendor", "autoload.php"]));

use Gt\Fetch\Http;
use Gt\Http\FormData;
use Gt\Http\Response;
use Gt\Json\JsonObject;

Expand All @@ -12,6 +13,11 @@

// Example: Post form data to the echo server.

$formData = new FormData();
$formData->set("name", "Mark Zuckerberg");
$formData->set("dob", "1984-05-14");
$formData->set("email", "[email protected]");

$http = new Http();
$http->fetch("https://postman-echo.com/post", [
// All of the request parameters can be passed directly here, or alternatively
Expand All @@ -20,11 +26,7 @@
"headers" => [
"Content-Type" => "application/x-www-form-urlencoded",
],
"body" => http_build_query([
"name" => "Mark Zuckerberg",
"dob" => "1984-05-14",
"email" => "[email protected]",
]),
"body" => $formData,
])
->then(function(Response $response) {
if(!$response->ok) {
Expand Down

0 comments on commit a9b8e10

Please sign in to comment.