Write xmlhttp result to text file

Discussion in 'ASP General' started by cwl@colon.dk, Aug 8, 2006.

  1. Guest

    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.
    , Aug 8, 2006
    #1
    1. Advertising

  2. Guest

    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




    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.
    , Aug 9, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    354
  2. J.Ram
    Replies:
    7
    Views:
    639
  3. Michael Tan
    Replies:
    32
    Views:
    927
    Ara.T.Howard
    Jul 21, 2005
  4. Eric
    Replies:
    1
    Views:
    312
    Martin Honnen
    Dec 24, 2003
  5. yawnmoth

    Msxml*.XMLHTTP vs. Microsoft.XMLHTTP

    yawnmoth, Nov 7, 2006, in forum: Javascript
    Replies:
    11
    Views:
    370
    Matt Kruse
    Nov 9, 2006
Loading...

Share This Page