Hi, vielleicht kann mir jemand helfen, ich hab mal versucht das Rest-Api Tutorial nachzuvollziehen, leider henge ich schon bei der Authentifizierung, die aber laut meinem Server-Admin alle Voraussetzungen hat. Mein Skript: [code]<?php if (isset($_SERVER[‚Authorization‘])) {
auth = preg_split('/\s+/', trim(_SERVER[‚Authorization‘]));
if (strtolower($auth[0]) == ‚basic‘ && count($auth) >= 2) { $data = explode(":", base64_decode($auth[1])); if (count(data) \>= 2) { _SERVER[‚PHP_AUTH_USER‘] = array_shift(data); _SERVER[‚PHP_AUTH_PW‘] = join(’:’, $data); } } } class ApiClient { const METHODE_GET = ‚GET‘; const METHODE_PUT = ‚PUT‘; const METHODE_POST = ‚POST‘; const METHODE_DELETE = ‚DELETE‘; protected $validMethods = array( self::METHODE_GET, self::METHODE_PUT, self::METHODE_POST, self::METHODE_DELETE ); protected $apiUrl; protected $cURL; public function __construct($apiUrl, $username, $apiKey) { $this->apiUrl = substr($apiUrl, -1) != ‚/‘ ? $apiUrl . ‚/‘ : $apiUrl; //Initializes the cURL instance $this->cURL = curl_init(); curl_setopt($this->cURL, CURLOPT_RETURNTRANSFER, true); curl_setopt($this->cURL, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); curl_setopt($this->cURL, CURLOPT_USERPWD, $username . ‚:‘ . $apiKey); curl_setopt($this->cURL, CURLOPT_HTTPHEADER, array( ‚Content-Type: application/json; charset=utf-8‘, )); } public function call($url, $method = self::METHODE_GET, $data = array()) { if (!in_array($method, $this->validMethods)) { throw new Exception('Invalid HTTP-Methode: ’ . $method); } $dataString = json_encode($data); curl_setopt($this->cURL, CURLOPT_URL, $this->apiUrl . $url); curl_setopt($this->cURL, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($this->cURL, CURLOPT_POSTFIELDS, $dataString); $result = curl_exec($this->cURL); $httpCode = curl_getinfo($this->cURL, CURLINFO_HTTP_CODE); return $this->prepareResponse($result, $httpCode); } protected function prepareResponse($result, $httpCode) { echo "
HTTP: $httpCode
"; if (null === $decodedResult = json_decode($result, true)) { $jsonErrors = array( JSON_ERROR_NONE => ‚Es ist kein Fehler aufgetreten‘, JSON_ERROR_DEPTH => ‚Die maximale Stacktiefe wurde erreicht‘, JSON_ERROR_CTRL_CHAR => ‚Steuerzeichenfehler, möglicherweise fehlerhaft kodiert‘, JSON_ERROR_SYNTAX => ‚Syntaxfehler‘, ); echo "
Could not decode json
"; echo "json_last_error: " . $jsonErrors[json_last_error()]; echo "
Raw:
"; echo "
" . print\_r($result, true) . "
"; return; } if (!isset($decodedResult[‚success‘])) { echo „Invalid Response“; return; } if (!$decodedResult[‚success‘]) { echo "
No Success
"; echo "
" . $decodedResult[‚message‘] . "
"; return; } echo "
Success
"; if (isset($decodedResult[‚data‘])) { echo "
" . print\_r($decodedResult['data'], true) . "
"; } return $decodedResult; } } $client = new ApiClient( //URL des Shopware Rest Servers ‚http://www.webshop-programmierung.at/api‘, //Benutzername ‚ds‘, //API-Key des Benutzers ‚xxxxxxxxxxxxxxxxxxxxx‘ ); $client->call(‚articles/3‘, ApiClient::METHODE_GET); echo $client; ?> [/code] und hier die Fehlermeldung: HTTP: 401 No Success Invalid or missing auth Beim direkten Aufruf über die URL komm ich auch nicht über die Passworteingabe hinaus.
uWamp hatte bei mir zuletzt auch funktioniert.
naja, berichte mal ob das geholfen hat.