尝试使用 Digest 对合作伙伴的使用 Delphi XE 的 Web 服务执行 get()。
我已将IdAuthenticationDigest
uses 子句包含在我所阅读的内容中,该子句应该会自动起作用-但我一定遗漏了一些东西,因为我得到了401 Unauthorized。
代码:
begin
// Init request:
IdHttp := TIdHttp.Create(nil);
try
idHttp.Request.ContentType := self.inputType; // 'application/xml'
idHttp.Request.Accept := self.outputType; //'application/json';
// Set request method:
idHttp.Request.Method := Method; // 'Get'
// Set username and password:
idHttp.Request.BasicAuthentication := False;
// IdHttp.Request.Username/Password also fails
IdHttp.Request.Authentication.Username := 'xx';
IdHttp.Request.Authentication.password := 'xx';
IdHttp.Request.ContentLength := Length(Body);
// Send request:
if Method = 'GET' then
Result := idHttp.Get(self.ServiceHost + URI)
else
if Method = 'POST' then
Result := idHttp.Post(self.ServiceHost + URI, SendStream);
finally
idHttp.Free;
end;
end;