function opigno_moxtra_app_api_post_json in Opigno Moxtra App 7
Post request with values and decode json response
Parameters
string $uri:
string $data_string:
Return value
StdClass
20 calls to opigno_moxtra_app_api_post_json()
- opigno_collaborative_workspaces_add_users in modules/
opigno_collaborative_workspaces/ includes/ opigno_collaborative_workspaces.api.inc - opigno_collaborative_workspaces_create_collaborative_workspace in modules/
opigno_collaborative_workspaces/ includes/ opigno_collaborative_workspaces.api.inc - opigno_collaborative_workspaces_remove_user in modules/
opigno_collaborative_workspaces/ includes/ opigno_collaborative_workspaces.api.inc - opigno_collaborative_workspaces_send_message in modules/
opigno_collaborative_workspaces/ includes/ opigno_collaborative_workspaces.api.inc - opigno_collaborative_workspaces_update_collaborative_workspace in modules/
opigno_collaborative_workspaces/ includes/ opigno_collaborative_workspaces.api.inc
File
- includes/
opigno_moxtra_app.http_client.inc, line 13
Code
function opigno_moxtra_app_api_post_json($uri, $data_string, $custom_content_type = NULL) {
$channel = curl_init();
curl_setopt($channel, CURLOPT_URL, $uri);
curl_setopt($channel, CURLOPT_POST, 1);
curl_setopt($channel, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($channel, CURLOPT_RETURNTRANSFER, true);
curl_setopt($channel, CURLOPT_SSL_VERIFYPEER, false);
if ($custom_content_type) {
curl_setopt($channel, CURLOPT_HTTPHEADER, array(
'Content-Type: ' . $custom_content_type,
));
}
$response = curl_exec($channel);
$http_code = curl_getinfo($channel, CURLINFO_HTTP_CODE);
if ($response === false) {
watchdog('opigno_moxtra_app', 'Curl error in ' . __FUNCTION__ . ':<br />' . 'Sent this url: ' . $uri . '<br />' . 'Error: <pre>' . curl_error($channel) . '</pre><br />' . 'Data sent:<pre>' . $data_string . '</pre>', array(), WATCHDOG_ERROR);
}
else {
// Add the http response code in the $response object
$responseDecoded = json_decode($response);
$response = (object) array_merge(array(
'http_code' => $http_code,
), empty($responseDecoded) ? array() : (array) $responseDecoded);
}
curl_close($channel);
return $response;
}