2012-02-20 57 views
0

下面是我的ASP页尝试对XML请求/响应如何制作XML文件的响应?

Request.asp

<% 
    pXML = "<XmlRequest><FileNo>123</FileNo></XmlRequest>" 
    Set http = CreateObject("MSXML2.ServerXMLHTTP") 
    http.open "GET", "http://test.com/response.asp?xml_request=" & pXML, 0 
    http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 
    http.send "" 
    http_response = http.responseText 
%> 

Response.asp

<% 
xml_request = Request.QueryString("xml_request") 

Set xd= Server.CreateObject("Msxml2.DOMDocument") 
xd.async = False 
xd.loadXML(Xml_Request) 

FileNo = xd.getElementsByTagName("XmlRequest").item(0).getElementsByTagName("FileNo").item(0).text 
''' here is the problem 
%> 

响应文件是在这个服务器路径Server.MapPath("123.xml")(这是一个大文件)

我如何发送响应文件到“Response.asp”的“Request.asp”

+0

你有什么理由不具有请求的asp + access的XML文件的URL直接是什么? (例如“http://test.com/123.xml”) – AnthonyWJones 2012-02-21 14:15:38

回答

0

读取文件后,可以使用Stream对象进行编写。
这是一种流式传输大型文件的有效方法。
顺便说一句,不要忘记处理所有潜在的错误。

Request.asp

Dim pXML 
    pXML = "<XmlRequest><FileNo>123</FileNo></XmlRequest>" 
Dim http, http_response 
Set http = CreateObject("MSXML2.ServerXMLHTTP") 
    http.Open "GET", "http://test.com/response.asp?xml_request=" & pXML, False 
    http.Send 
    http_response = http.responseText 
    If http.Status = 200 Then 'OK 
     Response.Write http_response 'ready with xml string 
    Else 
     Response.Write "An error ocured : <hr />"& http_response 
     Response.End 
    End If 
Set http = Nothing 

Response.asp

Dim xml_request 
    xml_request = Request.QueryString("xml_request") 

Dim xd 
Set xd= Server.CreateObject("Msxml2.DOMDocument") 
    xd.async = False 
    xd.loadXML(Xml_Request) 
    If xd.parseError.errorCode <> 0 Then Err.Raise 8, "", _ 
     "Request does not contain a valid xml string : '" & xml_request &"'" 
    Dim FileNo 
    Set FileNo = xd.documentElement.selectSingleNode("FileNo") 
     If FileNo Is Nothing Then 
      Err.Raise 8, "", "Node does not exists : FileNo" 
     Else 
      FileNo = FileNo.Text 
     End If 
    Dim FilePath 
     FilePath = Server.Mappath(FileNo & ".xml") 

Dim fso 
Set fso = Server.CreateObject("Scripting.FileSystemObject") 
    If Not fso.FileExists(FilePath) Then Err.Raise 8, "", "File Not Found : " & FilePath 

Const adTypeBinary = 1 
Dim str 
Set str = Server.CreateObject("Adodb.Stream") 
    str.Type = adTypeBinary 
    str.open 
    str.LoadFromFile FilePath 
    While Not str.EOS 
     If Not Response.IsClientConnected Then Response.End 
     Response.BinaryWrite str.Read(8192) 
    Wend 
+0

谢谢..它的工作... – user475464 2012-02-22 03:28:19

+0

例如:Dim fso set fso = Server.CreateObject(“Scripting.FileSystemObject”) 我的问题是,什么Dim fso和out declare之间的区别是dim? – user475464 2012-02-22 03:30:37

+0

123.xml是一个很大的文件...在这个编码中需要很多时间来加载 – user475464 2012-02-22 06:56:05