http服务用indy httpserver 简单实现,只负责将客户端Post的数据显示。
客户端想通过ClientSocket 构造http协议数据来Post 实现。
服务端:
procedure TFrmMain.IdServerCommandGet(AThread: TIdPeerThread;
  RequestInfo: TIdHTTPRequestInfo; ResponseInfo: TIdHTTPResponseInfo);
var
  sRequest:String;
begin
  if Requestinfo.Command = 'POST' then
  begin
    sRequest := RequestInfo.UnparsedParams;
    OutPutLog(sRequest);
    //获取回送客户端信息
    ResponseInfo.ContentText :=GetResponse('002',sRequest);
  end;
end;
客户端:ClienntSocket 阻塞      SendStr:=SendStr+'POST / HTTP/1.1'+#13#10;
      SendStr:=SendStr+'Accept: */*'+#13#10;
      SendStr:=SendStr+'Connection: Keep-Alive'+#13+#10;
      SendStr:=SendStr+#13#10;
      SendStr:=SendStr+sTmp; //stmp 存放xml 数据
      cs.Host :='127.0.0.1';
      cs.Port :=2001;
      cs.Open;
      if cs.Active then
        cs.Socket.SendText(SendStr);
      mmLog.Lines.Text :=cs.Socket.ReceiveText;    测试发现服务端接收不到数据,请教HTTP协议高手指点,是否协议构造有问题。
使用Indy http控件测试服务器可以正常接收Post数据回送数据也正常。

解决方案 »

  1.   

    太麻烦了,你不如直接使用xmlhttp来提交数据了
      

  2.   

    呵呵,要是能换控件我就早换 indy http 控件了,主要是不能换。
    谢谢月亮。
      

  3.   

    请教月亮
        memo1.lines.loadfromfile('a.xml');
        xmlHttp:=CreateOleObject('Msxml2.XMLHTTP');
        xmlHttp.open('POST',sUrl,false);
        xmlHttp.send(memo1.lines.txt); --执行这里提示参数不正确。
        sTmp:=xmlHttp.responseText; 
      

  4.   

    明白 xmlhttp send 错误原因了,要用 MSXML2.DOMDocument。
    还不明白 xmlhttp 异步执行的原理。如何接收服务回报。
      

  5.   

    用你的服务端调试一下,既然服务端是自己写的何必用http协议呢
      

  6.   

    服务端是别人的,我只是自己模拟个服务器用来测试下方法,对HTTP协议不是很熟悉。
      

  7.   

    var
      url:string;
      xmlHttp:Olevariant;
      responseText:Widestring;
    begin
      try
        xmlHttp:=CreateOleObject('Msxml2.XMLHTTP');
        xmlHttp.open('POST',url,false);
        xmlHttp.send('fdfdsfdsa');
        responseText:=xmlHttp.responseText;
        if xmlHttp.status='200' then
        begin
           //--
        end;
      finally
        xmlHttp:= unAssigned;
      end;
    end;就是这样用,没什么问题
      

  8.   

    var
      url:string;
      xmlHttp:Olevariant;
      responseText:Widestring;
    begin
      try
        xmlHttp:=CreateOleObject('Msxml2.XMLHTTP');
        xmlHttp.open('POST',url,false);
        xmlHttp.setRequestHeader('Content-Type', 'text/xml');
        xmlHttp.send(xmlStr);

        responseText:=xmlHttp.responseText;
        if xmlHttp.status='200' then
        begin
           //--
        end;
      finally
        xmlHttp:= unAssigned;
      end;
    end;