|
@@ -109,28 +109,32 @@ class Webservice
|
|
|
/**
|
|
|
* @param string $url
|
|
|
* @param string $method
|
|
|
+ * @param array $data
|
|
|
+ * @param array $credentials
|
|
|
*
|
|
|
* @return HttpResponse
|
|
|
*/
|
|
|
- public function makeGetRequest($url, $method = HttpRequestInterface::METHOD_GET, $data = array())
|
|
|
+ public function makeGetRequest($url, $method = HttpRequestInterface::METHOD_GET, $data = array(), $credentials = array())
|
|
|
{
|
|
|
- $response = '';
|
|
|
+ $headers = array();
|
|
|
if ($token = $this->securityTokenStorage->getToken()) {
|
|
|
- $headers = array();
|
|
|
- $request = new HttpRequest($method, $url);
|
|
|
- if (!empty($data)) {
|
|
|
- $headers[] = 'Content-Type: application/x-www-form-urlencoded';
|
|
|
- $request->setContent(http_build_query($data));
|
|
|
- }
|
|
|
- $response = new HttpResponse();
|
|
|
if (method_exists($token, 'getAccessToken')) {
|
|
|
$headers[] = 'Authorization: Bearer ' . $token->getAccessToken();
|
|
|
}
|
|
|
- $request->setHeaders($headers);
|
|
|
-
|
|
|
- $this->httpClient->send($request, $response);
|
|
|
- $response = $response->getContent();
|
|
|
+ } elseif (!empty($credentials) && isset($credentials['username']) && isset($credentials['password'])) {
|
|
|
+ $headers[] = 'Authorization: Basic ' . base64_encode($credentials['username'] . ":" . $credentials['password']);
|
|
|
+ } else {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ $request = new HttpRequest($method, $url);
|
|
|
+ if (!empty($data)) {
|
|
|
+ $headers[] = 'Content-Type: application/x-www-form-urlencoded';
|
|
|
+ $request->setContent(http_build_query($data));
|
|
|
}
|
|
|
+ $request->setHeaders($headers);
|
|
|
+ $response = new HttpResponse();
|
|
|
+ $this->httpClient->send($request, $response);
|
|
|
+ $response = $response->getContent();
|
|
|
|
|
|
return $response;
|
|
|
}
|