2

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 -

4

1 回答 1

0
ole.Send(FXMLDoc.XML.Text);  

你能得到你的失败阈值的近似值吗?是否在一致的范围内?您可以记录服务器实际收到的内容吗?

话虽如此,我想说你需要检查你的字节数——实际上有多少是通过网络发送的?如果增加的大小导致间歇性故障,很可能是您没有一次性发送所有内容 - 您可能必须跟踪实际发送的数量并循环,直到您确定您的整个流内容实际上已经传送了。

高温高压

于 2011-09-18T05:01:08.540 回答