$data = array(
'param1' => 'value1',
'param2' => 'value2'
);
$url = 'http://example.com/api?' . http_build_query($data);
$response = file_get_contents($url);
$data = array(
'param1' => 'value1',
'param2' => 'value2'
);
$options = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$response = file_get_contents('http://example.com/api', false, $context);
$ch = curl_init();
$data = array(
'param1' => 'value1',
'param2' => 'value2'
);
$url = 'http://example.com/api?' . http_build_query($data);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$ch = curl_init();
$data = array(
'param1' => 'value1',
'param2' => 'value2'
);
curl_setopt($ch, CURLOPT_URL, 'http://example.com/api');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$client = new GuzzleHttp\Client();
$data = array(
'param1' => 'value1',
'param2' => 'value2'
);
$response = $client->get('http://example.com/api', [
'query' => $data
]);
$body = $response->getBody();
$client = new GuzzleHttp\Client();
$data = array(
'param1' => 'value1',
'param2' => 'value2'
);
$response = $client->post('http://example.com/api', [
'form_params' => $data
]);
$body = $response->getBody();