代码之家  ›  专栏  ›  技术社区  ›  Mike Taylor

tIdHttpServer-在向POST发送回复之前关闭

  •  1
  • Mike Taylor  · 技术社区  · 16 年前

    我为CommandGet事件设置了一个简单的事件处理程序。

    当回复使用GET方法发送的数据时,我可以解析参数并毫无问题地发送XML数据(参见下面的代码)

        Download := ARequestInfo.Params.Values['dld'];
        Config := ARequestInfo.Params.Values['config'];
        Flash := ARequestInfo.Params.Values['flash'];
        Employees := ARequestInfo.Params.Values['employees'];
        Schedule := ARequestInfo.Params.Values['schedules'];
        AppTables := ARequestInfo.Params.Values['apptables'];
    
        Heartbeat :=  NewHeartbeat;
    
        Heartbeat.Version.Dld := Download;
        Heartbeat.Version.Config := Config;
        Heartbeat.Version.Flash := Flash;
        Heartbeat.Version.Employee := Employees;
        Heartbeat.Version.Schedule := Schedule;
        Heartbeat.Version.AppTables := AppTables;
    
        AResponseInfo.ContentType := 'application/xml';
        AResponseInfo.ResponseNo := 200;
        AResponseInfo.ContentText := '<?xml version="1.0" encoding="utf-8"?>' +
          #13+#10 + FormatXMLData(Heartbeat.XML);
    

        XMLDocument1.xml.Clear;
        XMLDocument1.Active := True;
        XMLDocument1.XML.text := ARequestInfo.FormParams;
    
        SynMemo1.Lines.Add(ARequestInfo.FormParams);
        SynMemo1.Lines.Add(#13+#10);
    
        if XMLDocument1.XML.Count > 0 then
        begin
          XMLDocument1.XML.Delete(0);
          XMLDocument1.XML.Delete(0);
    
          for i := pred(xmldocument1.xml.count) downto 0 do
          begin
            stmp := XMLDocument1.XML.Strings[i];
    
            if Length(stmp) > 0 then
            begin
              if Copy(stmp,1,1) = '<' then
                break
              else
                XMLDocument1.XML.Delete(i);
            end
            else
              XMLDocument1.XML.Delete(i);
    
          end;
    
          XMLDocument1.XML.Text := StringReplace(XMLDocument1.XML.Text,
            '<Punches ', '<Punches xmlns="http://ats/punch" ', [rfReplaceAll]);
    
    
    
        end;
    
        Punch := GetPunches(XMLDocument1);
    
        PunchReply := NewOperationStatus;
        PunchReply.Uid := Punch.Uid;
        PunchReply.NodeValue := 'OK';
    
        stmp := '<?xml version="1.0" encoding="utf-8"?>' +
          #13+#10 + FormatXMLData(PunchReply.XML);
        SynMemo1.Lines.Add(stmp);
        SynMemo1.Lines.Add(#13+#10);
    
        AResponseInfo.ContentType := 'text/html';
        AResponseInfo.ContentStream := TStringStream.Create(stmp);
    

    我用wireshark来查看发生了什么,看起来indy在发送响应之前发送了一个ACK,导致客户端断开连接。

    任何关于如何解决这个问题的建议,我都会回复POST数据并获取。


    Click here for image

    2 回复  |  直到 15 年前
        1
  •  2
  •   Mike Taylor    16 年前

    看起来http正在作为

    Transfer-Encoding: chunked
    

    因此没有内容长度。但是我使用的Indy版本不支持这种模式。

        2
  •  0
  •   Remy Lebeau    16 年前

    推荐文章