Skip to content

Instantly share code, notes, and snippets.

@FerraBraiZ
Last active April 27, 2018 13:06
Show Gist options
  • Save FerraBraiZ/18d7e9738ed376fc6d100be37aaac517 to your computer and use it in GitHub Desktop.
Save FerraBraiZ/18d7e9738ed376fc6d100be37aaac517 to your computer and use it in GitHub Desktop.
PHP CURL
<?php
$curl = curl_init();
$url = 'http://localhost:6969/ws/';
$opts = [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($payload),
CURLOPT_HTTPHEADER => ["content-type: application/json"],
];
if(strpos($url,'ttps://') > 0 ) $opts[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1;
curl_setopt_array($curl, $opts);
$response = curl_exec($curl);
curl_close($curl);
if( curl_errno( $curl ) ) return curl_error( $curl );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment