“PHP Curl” Kode Jawaban

Curl PHP Post

<?php

$post = [
    'username' => 'user1',
    'password' => 'passuser1',
    'gender'   => 1,
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.domain.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
$response = curl_exec($ch);
var_export($response);
feddynventor

PHP Curl

// set post fields
$post = [
    'username' => 'user1',
    'password' => 'passuser1',
    'gender'   => 1,
];

$ch = curl_init('http://www.example.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

// execute!
$response = curl_exec($ch);

// close the connection, release resources used
curl_close($ch);

// do anything you want with your response
var_dump($response);
RaFiNhA90

Contoh Curl PHP

function getUrl($url){
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $response = curl_exec($ch);
    curl_close($ch);
    return $response;
}   
Grepper

Contoh Curl PHP

$ch = curl_init();
$curlConfig = array(
    CURLOPT_URL            => "http://www.example.com/yourscript.php",
    CURLOPT_POST           => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS     => array(
        'field1' => 'some date',
        'field2' => 'some other data',
    )
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);

// result sent by the remote server is in $result
Foolish Ferret

PHP Curl

$data = json_encode(array(
    "ShortCode" => "600981",
    "ResponseType" => "Completed",
    "ConfirmationURL" => "https://mydomainx.com/confirmation",
    "ValidationURL" => "https://mydomainx.com/validation",
));

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
ibrahim hammed

PHP Curl

function curl( string $url, array $data)
{
	function send($url, $request)
	{
		$ch = curl_init();
		$headers = [
			'Accept: application/json',
			'Content-Type: application/json',
		];
		$options = [
			CURLOPT_URL => $url,
			CURLOPT_POST => true,
			CURLOPT_POSTFIELDS => $request,
			CURLOPT_FOLLOWLOCATION => true,
			CURLOPT_RETURNTRANSFER => true,
			CURLOPT_HEADER => true,
			CURLOPT_HTTPHEADER => $headers,
		];

		curl_setopt_array($ch, $options);
		$response = curl_exec($ch);
		curl_close($ch);
		
		return $response;
	}

	return send($url, json_encode($data));
}
mvmrik

Jawaban yang mirip dengan “PHP Curl”

Pertanyaan yang mirip dengan “PHP Curl”

Lebih banyak jawaban terkait untuk “PHP Curl” di PHP

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya