Einzelnen Beitrag anzeigen

MartinK

Registriert seit: 21. Jun 2009
Ort: Germering (Germany)
80 Beiträge
 
Delphi 10.2 Tokyo Enterprise
 
#8

AW: Daten abholen von einem CakePHP Server

  Alt 9. Okt 2014, 12:56
Damit es nicht zu leicht wird, hier die nächste Challenge zum selben Thema
Neben den einfach Dingen die per Get-Befehl nun wunderbar laufen, muss ich für andere API Befehle weitere Daten mitschicken.
Ich denke mal ich benötige dazu ein http.post


hier ein Auszug aus der API:

==================================
Login ausführen durch:
http://aServerName.de/users/login.json

Hierzu muss ein HTTPBody Field mitgeschickt werden (Anmerkung: was auch immer das genau ist...)

HTTPBody
{
UID = "04DAB959-9EF6-442C-8A19-D463C57E61D5";
activeversion = 312;
locale = de;
password = aPassword;
premium = 0;
username = "its.me@mail.com";
}


Wie macht man denn nun so etwas?
Meine erste Idee war daraufhin so etwas.


Delphi-Quellcode:
Var
  iDHTTP: TIdHttp;
  ResponseStr:String;
  Params: TStringStream;
begin

  IdHttp := TIdHttp.Create;
  Params := TStringStream.create('');
  try
    Params.WriteString(URLEncode('UID='           + '04DAB959-9EF6-442C-8A19-D463C57E61D5' + '&'));
    Params.WriteString(URLEncode('activeversion=' + '312'                                  + '&'));
    Params.WriteString(URLEncode('locale='        + 'de'                                   + '&'));
    Params.WriteString(URLEncode('password='      + EaCloudPassword.Text + '&'));
    Params.WriteString(URLEncode('premium='       + '1'                                    + '&'));
    Params.WriteString(URLEncode('username='      + EaCloudUsername.Text));

    iDHTTP.HandleRedirects := True;
    iDHTTP.Request.BasicAuthentication := True;
    iDHTTP.Request.Authentication := TIdBasicAuthentication.Create;
    iDHTTP.Request.Authentication.Username := EaCloudUsername.Text;
    iDHTTP.Request.Authentication.Password := EaCloudPassword.Text;
    IdHTTP.Request.ContentType := 'application/json';

    try
      IdHTTP.Response.KeepAlive := False;
      ResponseStr := IdHTTP.Post('http://aServerName.de/users/login.json', Params);
    except
      on E: Exception do
          showmessage('Error encountered during POST: ' + E.Message);
    end;

  finally
    IdHTTP.Free;
  end;

Der Code wird zwar ohne Fehler ausgeführt, die von CAKE-Server zurüchgelieferte Respons (ellenlang....) zeigt allerdings einen fehler

'<pre class="cake-error"><a href="javascript:void(0);" onclick="document.getElementById(''cakeErr54366d3e 5b147-trace'').style.display = (document.getElementById(''cakeErr54366d3e5b147-trace'').style.display == ''none'' ? '''' : ''none'');"><b>Warning</b> (4096)</a>: Argument 1 passed to Hash::get() must be an array, null given, called in /var/www/vhosts/acalc.de/httpdocs/cakephp-2.4.3/lib/Cake/Network/CakeRequest.php on line 853 and defined [<b>CORE/Cake/Utility/Hash.php</b>, line <b>43</b>]<div id="cakeErr54366d3e5b147-trace" class="cake-stack-trace" style="display: none;"><a href="javascript:void(0);" onclick="document.getElementById(''cakeErr54366d3e 5b147-code'').style.display = (document.getElementById(''cakeErr54366d3e5b147-code'').style.display == ''none'' ? '''' : ''none'')">Code</a> <a href="javascript:void(0);" onclick="document.getElementById(''cakeErr54366d3e 5b147-context'').style.display = (document.getElementById(''cakeErr54366d3e5b147-context'').style.display == ''none'' ? '''' : ''none'')">Context</a><pre id="cakeErr54366d3e5b147-code" class="cake-code-dump" style="display: none;"><code><span style="color: #000000"><span style="color: #0000BB">&nbsp;</span><span style="color: #007700">*&nbsp;@</span><span style="color: #0000BB">link&nbsp;http</span><span style="color: #007700">:</span><span style="color: #FF8000">//book.cakephp.org/2.0/en/core-utility-libraries/hash.html#Hash::get</span></span></code>'#$A'<code><span style="color: #000000"><span style="color: #0000BB">&nbsp;</span><span style="color: #007700">*/</span></span></code>'#$A'<span class="code-highlight"><code><span style="color: #000000"><span style="color: #0000BB">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">public&nbsp;static&nbsp;function&nbsp;</span><span style="color: #0000BB">get</span><span style="color: #007700">(array&nbsp;</span><span style="color: #0000BB">$data</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$path</span><span style="color: #007700">)&nbsp;{</span></span></code></span></pre><pre class="stack-trace">Hash::get() - CORE/Cake/Utility/Hash.php, line 43'#$A'CakeRequest::data() - CORE/Cake/Network/CakeRequest.php, line 853'#$A'UsersController::login() - APP/Controller/UsersController.php, line 52'#$A'ReflectionMethod::invokeArgs() - [internal], line ??'#$A'Controller::invokeAction() - CORE/Cake/Controller/Controller.php, line 490'#$A'Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 185'#$A'Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 160'#$A'[main] - APP/webroot/index.php, line 108</pre></div></pre><pre class="cake-error"><a href="javascript:void(0);" onclick="document.getElementById(''cakeErr54366d3e 5b9d7-trace'').style.display = (document.getElementById(''cakeErr54366d3e5b9d7-trace'').style.display == ''none'' ? '''' : ''none'');"><b>Warning</b> (4096)</a>: Argument 1 passed to Hash::get() must be an array, null given, called in /var/www/vhosts/acalc.de/httpdocs/cakephp-2.4.3/lib/Cake/Network/CakeRequest.php on line 853 and defined [<b>CORE/Cake/Utility/Hash.php</b>, line <b>43</b>]<div id="cakeErr54366d3e5b9d7-trace" class="cake-stack-trace" style="display: none;"><a href="javascript:void(0);" onclick="document.getElementById(''cakeErr54366d3e 5b9d7-code'').style.display = (document.getElementById(''cakeErr54366d3e5b9d7-code'').style.display == ''none'' ? '''' : ''none'')">Code</a> <a href="javascript:void(0);" onclick="document.getElementById(''cakeErr54366d3e 5b9d7-context'').style.display = (document.getElementById(''cakeErr54366d3e5b9d7-context'').style.display == ''none'' ? '''' : ''none'')">Context</a><pre id="cakeErr54366d3e5b9d7-code" class="cake-code-dump" style="display: none;"><code><span style="color: #000000"><span style="color: #0000BB">&nbsp;</span><span style="color: #007700">*&nbsp;@</span><span style="color: #0000BB">link&nbsp;http</span><span style="color: #007700">:</span><span style="color: #FF8000">//book.cakephp.org/2.0/en/core-utility-libraries/hash.html#Hash::get</span></span></code>'#$A'<code><span style="color: #0...

was ist denn das jetzt schon wieder ??

LG M
Martin Kuhn
  Mit Zitat antworten Zitat