【发布时间】:2021-05-03 07:18:19
【问题描述】:
如何在 Rest 命令中转换 CURL?
怎么了
curl -X GET --header "Accept: application/json" --header "X-Authorization: Bearer "Token"" "http://console.agrolog.io:8080/api/auth/user"
德尔福代码:
RESTClient1.BaseURL := 'http://console.agrolog.io:8080/api/';
RESTRequest1.Method := TRESTRequestMethod.rmGET;
RESTRequest1.Resource := 'auth/user';
RESTRequest1.Params.Clear;
with RESTRequest1.Params.AddItem do
begin
ContentType := ctAPPLICATION_JSON;
name := 'Authorization';
Value := 'X-Authorization: Bearer ' + '"'+Strtoken+'"' ;
Kind := pkHTTPHEADER;
end;
RESTRequest1.Execute;
错误是EHTTPProtocolException,消息为'HTTP/1.1 401'
【问题讨论】:
-
你的代码有什么问题?请提供您从 API 或您的程序收到的错误,并添加更具体的问题。
-
不确定您遇到了哪个错误。我只能猜测。但是,如果您的身份验证不起作用,请仔细检查您是否真的需要在不记名令牌周围加上引号。我平时遇到的格式是
Bearer xxxxxxxxxxxxxxxxxx(不带引号)。 -
错误是 EHTTPProtocolException with Message 'HTTP/1.1 401'