Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP General (http://www.velocityreviews.com/forums/f65-asp-general.html)
-   -   Write xmlhttp result to text file (http://www.velocityreviews.com/forums/t801791-write-xmlhttp-result-to-text-file.html)

cwl@colon.dk 08-08-2006 07:47 PM

Write xmlhttp result to text file
 
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.


cwl@colon.dk 08-09-2006 09:36 AM

Re: Write xmlhttp result to text file
 
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




cwl@colon.dk skrev:

> 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.




All times are GMT. The time now is 08:43 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.