MSXML / ServerXmlHttp POST 间歇性失败 (Delphi)
我有一些遗留的 Delphi 代码,它们使用 MSXML 组件将 XML 发布到安全的 Web 服务器。
该代码多年来一直运行良好。最近,我们进行了一些更改,使 XML 文件大小变大了一点,但幅度不大。 XML大小本身仍然相对较小,例如100k或更小。
我们检查了服务器日志,发现失败是身份验证错误,因为用户/密码有时未通过。这种情况间歇性地发生。唯一改变的是 XML 大小增加了一点。
我可以通过增量增长 xml 文件直到 POST 失败来验证这一点。我还可以通过执行相反的操作来进行验证(即,获取一个大文件并逐渐减少它,直到它成功发布)。
下面是一些示例代码。在本例中,我从文件加载 xml。在实际代码中我们使用流,但我确信这不是问题。
有谁知道为什么身份验证数据会在发送到 https 服务器的途中丢失?我似乎记得 MSXML 在某些情况下在协商身份验证方面存在问题,但我认为这与发布的 XML 的大小无关。
procedure TForm1.IntermittentFail;
Var
Resp : TStringStream ;
ole : OleVariant;
HTTPParams: TStrings;
aStream : TStream;
FXMLDoc : TXMLDocument ;
FXMLResp : TXMLDocument;
user, pass, URL, CommonStr : string;
begin
if not(odXMLFile.Execute) then
exit;
user := 'JoeUser';
pass := 'password
URL := 'https://aURL.com';
CommonStr := 'ParameterString';
FXMLDoc := TXMLDocument.Create(Nil);// create the outgoing doc
FXMLResp := TXMLDocument.Create(Nil);// create the response doc
Resp := nil;
FXMLDoc.LoadFromFile(odXMLFile.FileName);
ole := CreateOleObject('MSXML2.ServerXmlHttp');
ole.open('POST' ,URL , false, user, pass);
ole.SetTimeouts( 0, 60000, 300000, 300000);
//ole.SetTimeouts( 300000, 300000, 300000, 300000); //no effect.
ole.setOption(3, CommonStr);
//ole.setrequestheader('connection', 'close'); //no effect //sleep(5000); //no effect
ole.Send(FXMLDoc.XML.Text); //THIS WILL INTERMITTENTLY FAIL.
Resp := TStringStream.Create(ole.ResponseText);
finally
ole := Unassigned;
if Assigned(Resp) then
Resp.Free;
FXMLDoc.Free;
FXMLResp.Free;
end;
end;
谢谢 -
I have some legacy Delphi code that POSTs XML to a secure web server using the MSXML component.
The code has been working fine for years. Recently, we made some changes that makes the XML file size a bit larger, but not by much. The XML size itself is still relatively small, eg, 100k or less.
We checked the server logs and the failure is an authentication error due to the fact that user/pass are sometimes not passed. This happens intermittently. The only thing that has changed is that the XML size has grown a bit.
I can verify this by incrementally growing an xml file until the POST fails. I can also verify by doing the reverse, (ie, taking a large file and incrementally reducing it until it POSTs successfully).
Here is some sample code below. In this case I load the xml from file. In the actual code we use streams, but I am certain this is not the issue.
Does anyone know why the authentication data would get lost on the way to the https server? I seem to recall something about MSXML having problems with negotiating authentication in certain cases, but I don't think it had to do with the size of the XML being Posted.
procedure TForm1.IntermittentFail;
Var
Resp : TStringStream ;
ole : OleVariant;
HTTPParams: TStrings;
aStream : TStream;
FXMLDoc : TXMLDocument ;
FXMLResp : TXMLDocument;
user, pass, URL, CommonStr : string;
begin
if not(odXMLFile.Execute) then
exit;
user := 'JoeUser';
pass := 'password
URL := 'https://aURL.com';
CommonStr := 'ParameterString';
FXMLDoc := TXMLDocument.Create(Nil);// create the outgoing doc
FXMLResp := TXMLDocument.Create(Nil);// create the response doc
Resp := nil;
FXMLDoc.LoadFromFile(odXMLFile.FileName);
ole := CreateOleObject('MSXML2.ServerXmlHttp');
ole.open('POST' ,URL , false, user, pass);
ole.SetTimeouts( 0, 60000, 300000, 300000);
//ole.SetTimeouts( 300000, 300000, 300000, 300000); //no effect.
ole.setOption(3, CommonStr);
//ole.setrequestheader('connection', 'close'); //no effect //sleep(5000); //no effect
ole.Send(FXMLDoc.XML.Text); //THIS WILL INTERMITTENTLY FAIL.
Resp := TStringStream.Create(ole.ResponseText);
finally
ole := Unassigned;
if Assigned(Resp) then
Resp.Free;
FXMLDoc.Free;
FXMLResp.Free;
end;
end;
Thank you -
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你能得到失败阈值的近似值吗?是否在一个一致的范围内?您可以记录服务器实际收到的内容吗?
话虽如此,我想说你需要检查你的字节数 - 实际上有多少字节是通过网络发送的?如果大小增加导致间歇性故障,则很可能是您没有一次性发送所有内容 - 您可能必须跟踪实际发送的数量并循环,直到确定整个流内容实际上已经传送了。
华泰
Can you get an approximation of your failure threshold? Is it within a consistent range? Can you log what's actually been received by your server?
Having said that, I'd say you need to check your byte count - how many are actually getting sent over the wire? If increased size is causing intermittent failure, it may well be that you're not sending all of your content in one pass - you may have to keep track of the amount you've actually sent and loop until you are sure your entire stream content has actually been transmitted.
HTH
您在未设置“Content-Length”标头的情况下提交数据。如果没有此标头,XMLHttp 将不会发送任何内容,并且会因错误无效数据而失败。
You posing data without setting 'Content-Length' header. XMLHttp will no send any without this header and fail with error invalid data.