alerts: Set Content-type header in the API transport if the text to be sent is valid JSON (#8282)

* Set Content-type header to application/json in the API transport if the text to be sent is valid JSON.

* Update Api.php

* Update Api.php
This commit is contained in:
Nash Kaminski
2018-02-22 06:22:42 -06:00
committed by Neil Lathwood
parent 445e70c52e
commit fca10c61df

View File

@ -44,6 +44,9 @@ class Api implements Transport
curl_setopt($curl, CURLOPT_URL, ($method == "get" ? $host."?".$api : $host));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, strtoupper($method));
if (json_decode($api) !== null) {
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/json"));
}
curl_setopt($curl, CURLOPT_POSTFIELDS, $api);
$ret = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);