html - 使用 vbscript 从 Web 服务器下载 %username%.txt 时出错
问题描述
我在 pcloud 服务器上有一个文件 admin.txt,我的电脑用户名是 admin.所以我尝试使用以下 vscript 获取文件 admin.txt。
Dim myURL
Dim password
Dim username
Dim strUserName
Set objShell = CreateObject("WScript.Shell")
Set wshShell = CreateObject("WScript.Shell")
strUserName = wshShell.ExpandEnvironmentStrings("%USERNAME%.txt")
WScript.Echo "User Name: " & strUserName
myURL = "https://webdav.pcloud.com/Public%20Folder/%USERNAME%.txt"
username = "xyz@gmail.com"
password = "xyz"
Dim HttpReq
Set HttpReq = CreateObject("MSXML2.XMLHTTP.3.0")
HttpReq.Open "GET", myURL, False, username, password
HttpReq.Send
myURL = HttpReq.ResponseBody
If HttpReq.Status = 200 Then
Set oStrm = CreateObject("ADODB.Stream")
oStrm.Open
oStrm.Type = 1
oStrm.Write HttpReq.ResponseBody
oStrm.SaveToFile "D:/%USERNAME%.txt", 2 ' change your path here...
oStrm.Close
End If
错误信息:
第 16 行
char 1
错误:参数不正确。
代码:80070057
来源:msxml3.dll
注意: 在线
WScript.Echo "user name: " & strUserName
它显示了我的 admin.txt 名称。但是上线
myURL = "https://webdav.pcloud.com/public%20folder/%username%.txt"
它开始搜索%username%.txt
下载而不是admin.txt
我要下载的。
解决方案
问题已解决,代码按预期工作。
Dim myURL
Dim password
Dim username
Set wshShell = CreateObject("WScript.Shell")
strUserName = wshShell.ExpandEnvironmentStrings("%USERNAME%.txt")
myURL = wshShell.ExpandEnvironmentStrings("https://webdav.pcloud.com/Public%20Folder/%USERNAME%.txt")
username = "xyz@gmail.com"
password = "xyz"
Dim HttpReq
Set HttpReq = CreateObject("MSXML2.XMLHTTP.3.0")
HttpReq.Open "GET", myURL, False, username, password
HttpReq.Send
myURL = HttpReq.ResponseBody
If HttpReq.Status = 200 Then
Set oStrm = CreateObject("ADODB.Stream")
oStrm.Open
oStrm.Type = 1
oStrm.Write HttpReq.ResponseBody
oStrm.SaveToFile wshShell.ExpandEnvironmentStrings("D:/%USERNAME%.txt"), 2
oStrm.Close
End If
推荐阅读
- javascript - 将 Object 属性值推送到数组
- c++ - QByteArray 包含无法转换为汉字的十六进制数据
- reactjs - 反应原生 git 忽略
- node.js - WebPush:授权头中的key与订阅该用户的sender ID不对应
- python - 如何解决:Kivy Android OscService:应用程序崩溃,找不到类错误
- html - 为 Excel 工作表中的每一行创建一个 div
- c++ - 当我在 VS 代码上运行我的 C++ 程序时,如何摆脱 exit code=3221225781 ?
- android - 在回收站视图android中滚动时,项目会重新添加到复选框中
- html - rails 给出 activerecord 而不是 id
- python - Numpy 在 Python 中工作,但不在 Wing101 v. 7 中