c***@gmail.com
2006-08-05 21:26:47 UTC
I've been using XML alittle over a month now. I am trying to send a
file from one webserver to another using ServerXMLHTTP.
I can succefully send a file using the code below as long as the file
size
is below 350K. Any file 350K or larger won't transfer across. I am
completely lost as to why this is occurring. I have done some
searching and
haven't found any useful information. Any ideas would be great.
Thanks,
Chris
************************************************
PostData.asp: This page accepts a parameter which is the name of the
file to
be POSTed to the remote server.
<%
Option Explicit
Dim objStream
Dim objXMLDoc
Dim objDocElem
Dim strFileName
Dim objSXH
strFileName = Request("f")
Set objXMLDoc = Server.CreateObject("MSXML2.DOMDocument.4.0")
'The root node itslef will contain the base64 encoded data
objXMLDoc.loadXML "<Base64Data />"
'Read the file into the stream
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1
objStream.Open
objStream.LoadFromFile Server.MapPath("Files/" & strFileName)
'Do base64 encoding
Set objDocElem = objXMLDoc.documentElement
objDocElem.dataType = "bin.base64"
objDocElem.nodeTypedValue = objStream.Read
'Add FileName Attribute
objDocElem.setAttribute "FileName", strFileName
'POST the document on the remote server
Set objSXH = Server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
objSXH.open "POST", "http://SomeRemoteServer/SaveData.asp", False
objSXH.setRequestHeader "Content-Type", "text/xml"
objSXH.send objXMLDoc.xml
'POST Succeeded
If objSXH.status = 200 Then
Response.Write "The POST succeeded. "
Else
Response.Write "The POST failed: (" & objSXH.status & ") " & _
objSXH.statusText
End If
%>
The above code uses ADODB Stream to load a binary file, and MSXML DOM
to
base64 encode it and then it uses ServerXMLHTTP to post the created XML
document to the remote server. The above code generates XML document
which
looks similar to:
<Base64Data
xmlns:dt="urn:schemas-microsoft-com:datatypes"
dt:dt="bin.base64"
FileName="purpledot.gif">
R0lGODlhBQABAIAAAHkqhf///ywAAAAABQABAAACA0xgBQA7
</Base64Data>
SaveData.asp:
The following ASP page on the remote server loads the POSTed XML
document
using the Request stream, decodes the base64 data to binary and uses
ADODB
stream to save the binary data to the local file. The FileName
attribute's
value is used to name the local file.
<%
Option Explicit
Dim objXMLDoc
Dim objStream
Dim strFileName
'Create MSXML DOMDocument Object
Set objXMLDoc = Server.CreateObject("MSXML2.DOMDocument.4.0")
objXMLDoc.async = False
objXMLDoc.validateOnParse = False
'And load it from the request stream
If objXMLDoc.load (Request) Then
'Use ADO stream to save the binary data
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1
objStream.Open
'The nodeTypedValue automagically converts Base64 data
to binary data
'Write that binary data to the stream
objStream.Write
objXMLDoc.selectSingleNode("/Base64Data").nodeTypedValue
'Get the FileName attribute's value
strFileName =
objXMLDoc.selectSingleNode("/Base64Data/@FileName").nodeTypedValue
'Save the binary stream to the file
objStream.SaveToFile "D:\Temp\RecdFiles\" & strFileName
objStream.Close()
Set objStream = Nothing
Else
'Failed to load the document
End If
%>
************************************************
file from one webserver to another using ServerXMLHTTP.
I can succefully send a file using the code below as long as the file
size
is below 350K. Any file 350K or larger won't transfer across. I am
completely lost as to why this is occurring. I have done some
searching and
haven't found any useful information. Any ideas would be great.
Thanks,
Chris
************************************************
PostData.asp: This page accepts a parameter which is the name of the
file to
be POSTed to the remote server.
<%
Option Explicit
Dim objStream
Dim objXMLDoc
Dim objDocElem
Dim strFileName
Dim objSXH
strFileName = Request("f")
Set objXMLDoc = Server.CreateObject("MSXML2.DOMDocument.4.0")
'The root node itslef will contain the base64 encoded data
objXMLDoc.loadXML "<Base64Data />"
'Read the file into the stream
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1
objStream.Open
objStream.LoadFromFile Server.MapPath("Files/" & strFileName)
'Do base64 encoding
Set objDocElem = objXMLDoc.documentElement
objDocElem.dataType = "bin.base64"
objDocElem.nodeTypedValue = objStream.Read
'Add FileName Attribute
objDocElem.setAttribute "FileName", strFileName
'POST the document on the remote server
Set objSXH = Server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
objSXH.open "POST", "http://SomeRemoteServer/SaveData.asp", False
objSXH.setRequestHeader "Content-Type", "text/xml"
objSXH.send objXMLDoc.xml
'POST Succeeded
If objSXH.status = 200 Then
Response.Write "The POST succeeded. "
Else
Response.Write "The POST failed: (" & objSXH.status & ") " & _
objSXH.statusText
End If
%>
The above code uses ADODB Stream to load a binary file, and MSXML DOM
to
base64 encode it and then it uses ServerXMLHTTP to post the created XML
document to the remote server. The above code generates XML document
which
looks similar to:
<Base64Data
xmlns:dt="urn:schemas-microsoft-com:datatypes"
dt:dt="bin.base64"
FileName="purpledot.gif">
R0lGODlhBQABAIAAAHkqhf///ywAAAAABQABAAACA0xgBQA7
</Base64Data>
SaveData.asp:
The following ASP page on the remote server loads the POSTed XML
document
using the Request stream, decodes the base64 data to binary and uses
ADODB
stream to save the binary data to the local file. The FileName
attribute's
value is used to name the local file.
<%
Option Explicit
Dim objXMLDoc
Dim objStream
Dim strFileName
'Create MSXML DOMDocument Object
Set objXMLDoc = Server.CreateObject("MSXML2.DOMDocument.4.0")
objXMLDoc.async = False
objXMLDoc.validateOnParse = False
'And load it from the request stream
If objXMLDoc.load (Request) Then
'Use ADO stream to save the binary data
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1
objStream.Open
'The nodeTypedValue automagically converts Base64 data
to binary data
'Write that binary data to the stream
objStream.Write
objXMLDoc.selectSingleNode("/Base64Data").nodeTypedValue
'Get the FileName attribute's value
strFileName =
objXMLDoc.selectSingleNode("/Base64Data/@FileName").nodeTypedValue
'Save the binary stream to the file
objStream.SaveToFile "D:\Temp\RecdFiles\" & strFileName
objStream.Close()
Set objStream = Nothing
Else
'Failed to load the document
End If
%>
************************************************