vbscript - Output XMLHttp response line by line -
i need grab log file url , print log file line line. can file way:
dim filepath,filename filepath = "http://localhost/osat/spawn_pi_logs" filename = "/spawn.log" filepath = filepath & filename set req = createobject("msxml2.xmlhttp.6.0") req.open "get", filepath, false req.send if req.status = 200 response.write "found file<br>" response.write req.responsetext end if
that code writes text of log file screen in 1 huge ugly blob. want walk through it, format it, search it, etc , write out code similar this:
do while not textstream.atendofstream dim sline sline = textstream.readline sline = sline & "<br>" response.write sline loop
however, how convert req object (which has generic stream @ req.responsestream) , convert text stream?
you can save response text file incorporating ado stream , writing responsebody
:
if req.status = 200 createobject("adodb.stream") .type = 1 'adtypebinary .open .write req.responsebody .savetofile "c:\myfile.txt" .close end end if
then can open text file using opentextfile()
, read textstream
.
but, split responsetext
array split()
function , not worry saving , reading text file:
if req.status = 200 ' create line array... = split(req.responsetext, vbcrlf) = 0 ubound(a) ' process each line next end if
vbscript stream xmlhttprequest
No comments:
Post a Comment