Delphi。 REST:删除对象
Delphi. REST: Delete an object
寻求 Delphi 社区的帮助。
我正在使用 REST 与 SynchroTeam API 合作。
API Documentation here
我可以毫无问题地成功获取和 POST 数据。
但是我找不到删除工作的正确方法。
Delete a Job
下载所有作业后,我正在尝试删除其中的一些作业。所以,我知道每个作业的 ID、MyID 和 NUM 属性。
但是,当我使用以下代码时:
RESTClient:= TRESTClient.Create('https://ws.synchroteam.com/api/v3');
with RESTClient do
begin
Accept:= 'application/json';
AcceptCharset:= 'UTF-8';
Authenticator:= HTTPBasicAuthenticator;
SecureProtocols := [THTTPSecureProtocol.TLS12];
end;
RESTRequest.Method:= TRESTRequestMethod.rmDELETE;
RESTRequest.Resource:= 'job/delete?Myid=467925';
RESTRequest.AddParameter('Content-Type', 'application/json',
TRESTRequestParameterKind.pkHTTPHEADER,
[poDoNotEncode]);
RESTRequest.AddParameter('Accept', 'text/json',
TRESTRequestParameterKind.pkHTTPHEADER,
[poDoNotEncode]);
RESTRequest.Execute;
我收到错误 404:作业不存在。我 100% 相信 MyID。我还尝试了 Myid="467925" 或 ID 属性: 同样的结果。
如果我这样尝试,我会收到另一个错误:HTTP/1.1 500 内部服务器错误
RESTRequest.Method:= TRESTRequestMethod.rmDELETE;
RESTRequest.Resource:= 'job/delete';
RESTRequest.AddParameter('Content-Type', 'application/json',
TRESTRequestParameterKind.pkHTTPHEADER,
[poDoNotEncode]);
RESTRequest.AddParameter('Accept', 'text/json',
TRESTRequestParameterKind.pkHTTPHEADER,
[poDoNotEncode]);
RESTRequest.AddParameter('myId', '467925',
TRESTRequestParameterKind.pkREQUESTBODY,
[poDoNotEncode]);
RESTRequest.Execute;
我还尝试使用 TRESTRequestParameterKind.pkHTTPHEADER 作为 MyId 参数
使用 REST.Client.TRESTRequest 删除记录的正确方法是什么?
这是Fiddler抓取的请求
DELETE https://ws.synchroteam.com/api/v3/job/delete?myId=467927 HTTP/1.1
Connection: Keep-Alive
Content-Type: application/json
Accept: text/json
Accept-Charset: UTF-8
Authorization: Basic XXXXXXXXXX
Cookie: incap_ses_466_1982613=JG+hNrWzP3ntmaXA4pB3BhU0SmAAAAAArMFLFUXF8+BXuhjHFDJEIA==; visid_incap_1982613=eLvuGVc7ToSqZT5dVRPkcRU0SmAAAAAAQUIPAAAAAADEtuE8tUgs/WIAYTcpXzLh; ASP.NET_SessionId=tpffwpqwj0pphbx5s3llzp3f
User-Agent: Embarcadero RESTClient/1.0
Content-Length: 348
Host: ws.synchroteam.com
并回应
HTTP/1.1 404 Not Found
Cache-Control: private, s-maxage=0
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/10.0
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 1615476362
X-Quota-Limit: 15000
X-Quota-Remaining: 14679
Date: Thu, 11 Mar 2021 15:25:02 GMT
Content-Length: 66
X-CDN: Imperva
X-Iinfo: 10-12437416-12437480 SNNN RT(1615476301530 1054) q(0 0 0 -1) r(1 1) U6
{"error":"Not Found","message":"The requested Job does not exist"}
根据 SynchroTeam 支持,我发送的负载是
(我已经删除了隐私数据)
myId=467927{"id":121464,"firstName":"FFFFF","lastName":NNNNN","login":"LLLLLL","password":"PPPPP","language":"LL","email":"EEEEE","phone":"PPPPPP","profile":"administrator","customFieldValues":[],"skilledTrades":[],"teams":[],"startLocation":{"fullAddress":"","latitude":"","longitude":""},"lastLocation":null,"deleted":""}
我看不到这个带有我的凭据的额外有效负载是在哪里定义的,以及为什么我对 GET 和 POST
等其他请求没有同样的问题
我发现了我的(愚蠢的)错误。
我还有另一个对象(我作为用户)作为另一个请求的主体。
我使用
更正了这一点
RESTRequest.Body.ClearBody;
RESTRequest.Params.Clear;
结案
寻求 Delphi 社区的帮助。
我正在使用 REST 与 SynchroTeam API 合作。 API Documentation here
我可以毫无问题地成功获取和 POST 数据。 但是我找不到删除工作的正确方法。 Delete a Job
下载所有作业后,我正在尝试删除其中的一些作业。所以,我知道每个作业的 ID、MyID 和 NUM 属性。 但是,当我使用以下代码时:
RESTClient:= TRESTClient.Create('https://ws.synchroteam.com/api/v3');
with RESTClient do
begin
Accept:= 'application/json';
AcceptCharset:= 'UTF-8';
Authenticator:= HTTPBasicAuthenticator;
SecureProtocols := [THTTPSecureProtocol.TLS12];
end;
RESTRequest.Method:= TRESTRequestMethod.rmDELETE;
RESTRequest.Resource:= 'job/delete?Myid=467925';
RESTRequest.AddParameter('Content-Type', 'application/json',
TRESTRequestParameterKind.pkHTTPHEADER,
[poDoNotEncode]);
RESTRequest.AddParameter('Accept', 'text/json',
TRESTRequestParameterKind.pkHTTPHEADER,
[poDoNotEncode]);
RESTRequest.Execute;
我收到错误 404:作业不存在。我 100% 相信 MyID。我还尝试了 Myid="467925" 或 ID 属性: 同样的结果。
如果我这样尝试,我会收到另一个错误:HTTP/1.1 500 内部服务器错误
RESTRequest.Method:= TRESTRequestMethod.rmDELETE;
RESTRequest.Resource:= 'job/delete';
RESTRequest.AddParameter('Content-Type', 'application/json',
TRESTRequestParameterKind.pkHTTPHEADER,
[poDoNotEncode]);
RESTRequest.AddParameter('Accept', 'text/json',
TRESTRequestParameterKind.pkHTTPHEADER,
[poDoNotEncode]);
RESTRequest.AddParameter('myId', '467925',
TRESTRequestParameterKind.pkREQUESTBODY,
[poDoNotEncode]);
RESTRequest.Execute;
我还尝试使用 TRESTRequestParameterKind.pkHTTPHEADER 作为 MyId 参数
使用 REST.Client.TRESTRequest 删除记录的正确方法是什么?
这是Fiddler抓取的请求
DELETE https://ws.synchroteam.com/api/v3/job/delete?myId=467927 HTTP/1.1
Connection: Keep-Alive
Content-Type: application/json
Accept: text/json
Accept-Charset: UTF-8
Authorization: Basic XXXXXXXXXX
Cookie: incap_ses_466_1982613=JG+hNrWzP3ntmaXA4pB3BhU0SmAAAAAArMFLFUXF8+BXuhjHFDJEIA==; visid_incap_1982613=eLvuGVc7ToSqZT5dVRPkcRU0SmAAAAAAQUIPAAAAAADEtuE8tUgs/WIAYTcpXzLh; ASP.NET_SessionId=tpffwpqwj0pphbx5s3llzp3f
User-Agent: Embarcadero RESTClient/1.0
Content-Length: 348
Host: ws.synchroteam.com
并回应
HTTP/1.1 404 Not Found
Cache-Control: private, s-maxage=0
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/10.0
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 1615476362
X-Quota-Limit: 15000
X-Quota-Remaining: 14679
Date: Thu, 11 Mar 2021 15:25:02 GMT
Content-Length: 66
X-CDN: Imperva
X-Iinfo: 10-12437416-12437480 SNNN RT(1615476301530 1054) q(0 0 0 -1) r(1 1) U6
{"error":"Not Found","message":"The requested Job does not exist"}
根据 SynchroTeam 支持,我发送的负载是 (我已经删除了隐私数据)
myId=467927{"id":121464,"firstName":"FFFFF","lastName":NNNNN","login":"LLLLLL","password":"PPPPP","language":"LL","email":"EEEEE","phone":"PPPPPP","profile":"administrator","customFieldValues":[],"skilledTrades":[],"teams":[],"startLocation":{"fullAddress":"","latitude":"","longitude":""},"lastLocation":null,"deleted":""}
我看不到这个带有我的凭据的额外有效负载是在哪里定义的,以及为什么我对 GET 和 POST
等其他请求没有同样的问题我发现了我的(愚蠢的)错误。 我还有另一个对象(我作为用户)作为另一个请求的主体。 我使用
更正了这一点RESTRequest.Body.ClearBody;
RESTRequest.Params.Clear;
结案