public static function WebServiceUtilityBase::sendRequest in Smart IP 8.4
Same name and namespace in other branches
- 8.2 src/WebServiceUtilityBase.php \Drupal\smart_ip\WebServiceUtilityBase::sendRequest()
- 8.3 src/WebServiceUtilityBase.php \Drupal\smart_ip\WebServiceUtilityBase::sendRequest()
Perform HTTP request to the Smart IP's data source module web service.
Parameters
string $url: URL provided by Smart IP's data source module web service for geolocation query.
Return value
string Raw Geolocation data returned by Smart IP's data source module web service.
Overrides WebServiceUtilityInterface::sendRequest
3 calls to WebServiceUtilityBase::sendRequest()
- WebServiceUtility::getGeolocation in modules/
smart_ip_ipinfodb_web_service/ src/ WebServiceUtility.php - Perform HTTP request and decoding the raw Geolocation data returned by Smart IP's data source module web service.
- WebServiceUtility::getGeolocation in modules/
smart_ip_abstract_web_service/ src/ WebServiceUtility.php - Perform HTTP request and decoding the raw Geolocation data returned by Smart IP's data source module web service.
- WebServiceUtility::getGeolocation in modules/
smart_ip_maxmind_geoip2_web_service/ src/ WebServiceUtility.php - Perform HTTP request and decoding the raw Geolocation data returned by Smart IP's data source module web service.
File
- src/
WebServiceUtilityBase.php, line 20 - Contains \Drupal\smart_ip\WebServiceUtilityBase.
Class
- WebServiceUtilityBase
- Web service utility methods class wrapper.
Namespace
Drupal\smart_ipCode
public static function sendRequest($url = NULL) {
if (!empty($url)) {
try {
$response = \Drupal::httpClient()
->get($url, [
'headers' => [
'Accept' => 'application/json',
],
]);
$data = (string) $response
->getBody();
if (empty($data)) {
\Drupal::logger('smart_ip')
->error(t('Empty response from @url', [
'@url' => $url,
]));
}
else {
return $data;
}
} catch (\Exception $e) {
\Drupal::logger('smart_ip')
->error(t('Sending request failed: @error', [
'@error' => $e
->getMessage(),
]));
}
}
return '';
}