Write xmlhttp result to text file

C

cwl

I want to get the content of a webpage containing plain text and write
the content to a text file. My code looks like this:

Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
xmlhttp.setRequestHeader "Content-type","text/txt"
xmlhttp.Open "get", "http://www.mysite.com/default.asp", False
xmlhttp.Send
text = xmlhttp.responseText

dim fs, fname
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fname=fs.CreateTextFile("c:\test.txt",true)
fname.WriteLine(text)
fname.Close
set fname=nothing
set fs=nothing

The first and second part of the code runs fine if they are executed in
seperate files. So the text is retrieved and it's possible to write a
text file to the server.

But when they are combined in one file - which they of course have to
be - I'm prompted to logon on the server! And the file containing the
above script is suddenly inaccessible. I'm only able to delete it from
the webserver.

Does anyone have a clue why this happens?

The script runs on IIS 6.
 
C

cwl

I solved it. It had to do with special characters in the retrieved
text. Had to convert the binary data to string.


Set xmlhttp = Server.CreateObject("Microsoft.XMLHTTP")
xmlhttp.Open "get", "http://www.mysite.com/default.asp", False
xmlhttp.Send
text = bts(xmlhttp.responseBody)
Set xmlhttp = nothing

dim fs, fname
set fs = Server.CreateObject("Scripting.FileSystemObject")
set fname=fs.CreateTextFile("c:\test.txt",true)
fname.Write(text)
fname.Close
set fname=nothing
set fs=nothing

function bts(data)
'Converts binary data to string
sOut = ""
For i = 0 to UBound(data)
sOut = sOut & chrw(ascw(chr(ascb(midb(data,i+1,1)))))
Next
bts=sOut
end function




(e-mail address removed) skrev:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top