从远程服务器保存CSV文件(数据馈送)时出错。对于某些数据馈送,它可以按预期工作,但对于其他数据馈送,则标记为错误。
该代码检索远程数据馈送并将其本地保存为datafeed.csv
这是到目前为止的脚本。
Set xhr = Server.CreateObject("MSXML2.ServerXMLHTTP")
xhr.Open "GET", remote_datafeed, False
xhr.Send
IF NOT xhr.Status = 200 THEN
Response.write"Error retrieving remote CSV file"
else
sResponse = split(xhr.responseText, vbcrlf)
set datafeed = fs.CreateTextFile("files/datafeed.csv", true)
For i = 0 to uBound(sResponse)
datafeed.WriteLine sResponse(i)
Next
Response.write "Remote file has successfully been save locally <br>"
datafeed.close
set datafeed = nothing
我有时在下一行出现错误。
datafeed.WriteLine sResponse(i)
我得到的错误是:
Microsoft VBScript runtime error '800a0005'
Invalid procedure call or argument
答案 0 :(得分:0)
浏览远程数据源后,发现它与utf-8字符集有关。更改为以下代码,使用utf-8字符集解决了此问题。
Dim objStream
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 2
objStream.Mode = 3
objStream.Open
objStream.Position = 0
objStream.Charset = "UTF-8"
objStream.WriteText xhr.responseText
objStream.SaveToFile "files/datafeed.csv"
objStream.Close
Set objStream = nothing