繁体   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