我将XML文件发送到servlet服务端,可是servlet接受到的代码中间出现错误,
代码如下procedure THttpConnectForm.SendXML(XMLfile : string);
var
  response:TStringStream;
  MMPFDS:TIdMultiPartFormDataStream;
begin
  MMPFDS:=TIdMultiPartFormDataStream.Create;
  response:=TStringStream.Create('');
  IdHTTP.Request.ContentType:=MMPFDS.RequestContentType;
  MMPFDS.AddFile('xmlfile',XMLfile,'xml/plain');
  MMPFDS.Position:=0;
  try
    try
      IdHTTP.Post(URL,MMPFDS,response);
    except    end;
  finally
    showMessage(response.DataString);
    MMPFDS.Free;
    response.Free;
  end;
end;xml为:
<?xml version="1.0" encoding="GBK"?>
<versions>
  <version id="ACF85A9F0B0E42D49B0BBD6D117EBF86">1</version>
  <version id="AC8102EB281C469FA738E12D5C0686F0">1</version>
</versions>接收到的是:
      
        1
        1请问是什么回事?

解决方案 »

  1.   

    你的這段Delphi Client Source是没問題的。我用以下的Servlet進行的測試。
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      InputStream in = request.getInputStream();
      StringBuffer buffer = new StringBuffer();
      int c;
      while ((c=in.read()) != -1) {
        buffer.append((char)c);
      }
      String str = buffer.toString();
      response.getWriter().write(str);
    }接收後返回以下的消息:
    Content-Disposition: form-data; name="xmlfile"; filename="test1.xml"
    Content-Type: xml/plain<?xml version="1.0" encoding="GBK"?>
    <versions>
      <version id="ACF85A9F0B0E42D49B0BBD6D117EBF86">1</version>
      <version id="AC8102EB281C469FA738E12D5C0686F0">1</version>
    </versions>
      

  2.   

    var
      pXML: WideString;
      oReq: IXMLHTTPRequest;
      reMsg: string;
    begin
        oReq := CreateOleObject('Microsoft.XMLHTTP') as IXMLHTTPRequest;
        oReq.Open('POST', 'http://www.abc.com/aaa.asp', False, varNull, varNull);
        oReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        pXML := '<?xml version="1.0" encoding="GBK"?>'
    +'<versions>'
     + '<version id="ACF85A9F0B0E42D49B0BBD6D117EBF86">1</version>'
      +'<version id="AC8102EB281C469FA738E12D5C0686F0">1</version>'
    +'</versions>';
          pXML := AnsiToUtf8(pXML);
          oReq.send(pXML);
          reMsg := '';接收返回内容
          reMsg := oReq.responseText;end;
      

  3.   

    问题解决后别忘记给分哈
    IXMLHTTPRequest在MSXML2_TLB单元
    如果没有,在improt type library 里面Microsoft XML V3.0来创建MSXML2_TLB单元。