-
Notifications
You must be signed in to change notification settings - Fork 104
Open
Description
When PHP configuration option allow_url_fopen is truthy (the default), it's easy to use it as a transport. It's probably less error-prone than a raw socket, too.
$response_body = file_get_contents(
"https://api.createsend.com/api/v3.2/${endpoint}.json"
, false
, stream_context_create([
'http' => [
'method' => 'POST',
'header' => [
'Authentication: Basic ' . base64_encode("${api_key}:"),
'Content-Type: application/json',
],
'content' => json_encode($request_data),
'ignore_errors' => true, # prevents returning boolean false for error http statuses
],
])
);
$response_headers = $http_response_header; # https://www.php.net/manual/en/reserved.variables.httpresponseheader.phpObviously it'd need a little bit more logic to choose HTTP method, be more generic, etc., but the code's a lot simpler than cURL and raw sockets.
Radon8472
Metadata
Metadata
Assignees
Labels
No labels