“php post curl json” Kod odpowiedzi

PHP Curl Post Json

$ch = curl_init( $url );
# Setup request to send json via POST.
$payload = json_encode( array( "customer"=> $data ) );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
# Return response instead of printing.
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
# Send request.
$result = curl_exec($ch);
curl_close($ch);
Friendly Hawk

php post curl json

function postCurl(array $postFields, string $url)
{
    $post = $postFields;
    if (count($post) == 0) {
        return false;
    }
    $url = trim($url);
    $postdata = json_encode($post, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    $result = curl_exec($ch);
    $decodedResult = json_decode($result, JSON_UNESCAPED_UNICODE);
    if ($decodedResult['status'] == 'ok') {
        return $decodedResult;
    } else {
        return false;
    }
    curl_close($ch);
}
Lucky Llama

Odpowiedzi podobne do “php post curl json”

Pytania podobne do “php post curl json”

Więcej pokrewnych odpowiedzi na “php post curl json” w PHP

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu