Answer the question
In order to leave comments, you need to log in
How to send a post request with json using for example guzzle?
$params['header'] = $this->body['header'];
$params['body'] = $this->body['body'];
$api = \Illuminate\Support\Facades\Config::get('app.constants.api');
$url = $api['base'] . $api['prefix'] . $api['version'] . '/create-news-by-admin';
$headers = ['Content-type' => 'application/json'];
$client = new Client();
$request = $client->post($url, array(
'content-type' => 'application/json'
), array());
$request->setBody(json_encode($params));
echo $url;
try {
$response = $request->send();
} catch (ClientException $e) {
echo $e->getMessage();
}
Answer the question
In order to leave comments, you need to log in
$response = $client->request('PUT', '/put', ['json' => ['foo' => 'bar']]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question