簡體   English   中英

Delphi DataSnap TDSServiceException

[英]Delphi DataSnap TDSServiceException

我在 RAD Studio 10 Seattle 上使用 Delphi 與 REST API 和 DataSnap 一起工作。 它適用於大多數 HTTP 動詞,除了 DELETE。 There's the function for it, according to the DataSnap documentation, but when I do a request with the DELETE HTTP Verb, it gives-me the exception "Project RESTApi.exe raised exception class TDSServiceException with message 'Command closed or unassigned".

遵循 DataSnap API 的 DELETE function 代碼。

function TSM.CancelLista(const ID_LISTA: integer): TJSONObject;
const
 _DELETE = 'DELETE FROM listas WHERE id = :id';
begin
 with FormPrincipal do
 begin
  DB_Query.Active := false;
  DB_Query.SQL.Text := _DELETE;
  DB_Query.ParamByName('id').Value :=  ID_LISTA;

  Try
    DB_Query.ExecSQL;
    Result.AddPair('Response', 'Lista atualizada com sucesso');
  Except on E : Exception do
    Result.AddPair('Response', E.Message);
  End;
 end;
end;

I'm making the requests with a PHP Code Igniter 4.0.4 web app, but already tried it with the Delphi REST Debugger, with the same result.

問題根本不在 API 中,但請求的方法沒有正確生成,該方法作為“DELETE”發送,因此 DataSnap API 沒有將其識別為命令。 作為 Code Igniter 4.0.4 CURLRequest class 發出的請求,如下所示:

$reqConfig = [            
        'headers' => [
            'Accept' => 'application/json',
            'Content-Type' => 'application/json'
        ]            
    ]; 
$verb = '`DELETE`'
$curl->request($verb, 'Listas/'.id_lista, $reqConfig);

解決了改變$verb去掉“`”的問題。

API DELETE function 現在是:

function TSM.CancelLista(const ID_LISTA: integer): TJSONObject;
const
  _DELETE = 'DELETE FROM listas WHERE id = :id';
begin
  Result := TJSONObject.Create;
  with FormPrincipal do
  begin
    DB_Query.Active := false;
    DB_Query.SQL.Text := _DELETE;
    DB_Query.ParamByName('id').Value :=  ID_LISTA;

    Try
      DB_Query.ExecSQL;
      Result.AddPair('Response', 'Lista deletada com sucesso');
    Except on E : Exception do
      Result.AddPair('Response', E.Message);
    End;
  end;
end;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM