gpt4 book ai didi

delphi - 如何对此 HTTPS SOAP 服务进行身份验证?

转载 作者:行者123 更新时间:2023-12-03 15:01:30 27 4
gpt4 key购买 nike

我正在尝试创建一个小工具来监控我已经使用了多少带宽以及我的 ISP 还剩多少带宽。他们有一个 SOAP 服务,我必须验证我的用户名和密码并验证客户端,然后我将获得 2 个 GUID,必须将其传递到将从数组返回使用统计信息的函数中。然后这些会被缓存 1 小时,我必须再次进行身份验证。

我使用了 Delphi 2010 中的 WSDL 导入器,它为我生成了一个单元。 (我不太确定我应该发布这个,因为它很大)?

我正在尝试使用以下代码使用我的用户名和密码验证第一部分:

procedure TForm1.btnAuthClick(Sender: TObject);
var
fGUID: string;
begin
HTTPRIO1.URL := 'https://webservices.zen.co.uk/broadband/v3.11/serviceengine.asmx?WSDL';
try
fGUID := (HTTPRIO1 as ServiceEngineSoap).Authenticate(edtUserName.Text,edtPassword.Text);
Label1.Caption := fGUID;
except
on E: Exception do
Memo1.Lines.Text := E.Message;
end;
end;

上面的代码总是返回以下错误:

Header http://schemas.xmlsoap.org/ws/2004/08/addressing:Action for ultimate recipient is required but not present in the message.


我尝试使用 WSDLLocation 代替服务和端口:

procedure TForm1.btnAuthClick(Sender: TObject);
var
fGUID: string;
begin
HTTPRIO1.WSDLLocation := 'https://webservices.zen.co.uk/broadband/v3.11/serviceengine.asmx?WSDL';
HTTPRIO1.Service := 'ServiceEngine';
HTTPRIO1.Port := 'ServiceEngineSoap';
try
fGUID := (HTTPRIO1 as ServiceEngineSoap).Authenticate(edtUserName.Text,edtPassword.Text);
Label1.Caption := fGUID;
except
on E: Exception do
Memo1.Lines.Text := E.Message;
end;
end;

这总是会生成以下错误:

Unable to retrieve the URL endpoint for Service/Port 'ServiceEngine'/'ServiceEngineSoap' from WSDL 'https://webservices.zen.co.uk/broadband/v3.11/serviceengine.asmx?WSDL'


我在这里做错了什么?如果我实际上应该发送 header ,那么我将如何执行此操作来向服务验证自己的身份?

最佳答案

根据docs

if the server requires authentication, use the properties of the THTTPReqResp object to provide the necessary information

在 THTTPReqResp 对象中设置用户/密码 (HTTPRIO1.HTTPWebNode.UserName := 'xxx'; HTTPRIO1.HTTPWebNode.Password := 'yyy')

另请注意文档中有关使用 HTTPS 的信息:

THTTPReqResp uses WinInet to establish a connection to the server. Wininet.dll must be installed on the client system. wininet.dll is found in the Windows system directory if you have IE3 or higher installed. WinInet has the advantage that it provides support for secure connections (https). To use WinInet, compile your project without the USE_INDY symbol defined

但是,根据下面的帖子,该用户/密码似乎只能在代理情况下使用。如果 Jean-Marie Babet 仍未修复此问题,请点击 2007 年给出的原始解决方法的链接:

https://forums.codegear.com/thread.jspa?threadID=58755&tstart=0

解决方法如下:

All you have to do is handle the OnBeforePost event on the HTTPRIO.HTTPWebNode component and use InternetSetOption. Here's an example from a sample that talks to MapPoint (MapPoint.NET uses 'digest' authentication - a variant of 'basic' authentication):

procedure TTestMapPointRender.HTTPRIO1HTTPWebNode1BeforePost(
const HTTPReqResp: THTTPReqResp; Data: Pointer);
var
UserName: string;
PassWord: string;
begin
UserName := GetWSToken('MapPoint', 'UserName');
Password := GetWSToken('MapPoint', 'Password');
if not InternetSetOption(Data,
INTERNET_OPTION_USERNAME,
PChar(UserName),
Length(UserName)) then
raiseException(SysErrorMessage(GetLastError));

if not InternetSetOption(Data,
INTERNET_OPTION_PASSWORD,
PChar(Password),
Length (Password)) then
raiseException(SysErrorMessage(GetLastError));
end;

关于delphi - 如何对此 HTTPS SOAP 服务进行身份验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7462991/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com