Как сделать ответ из xml файла? - PullRequest
0 голосов
/ 21 февраля 2012

Ниже приведены мои asp-страницы, пытающиеся выполнить запрос / ответ 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") (это большой файл)

Как отправить файл ответов в «Request.asp» из «Response.asp»

1 Ответ

0 голосов
/ 21 февраля 2012

После прочтения файла вы можете писать с использованием объекта 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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...