Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 使用vbscript从web服务器下载%username%.txt时出错_Html_Vbscript - Fatal编程技术网

Html 使用vbscript从web服务器下载%username%.txt时出错

Html 使用vbscript从web服务器下载%username%.txt时出错,html,vbscript,Html,Vbscript,我在pcloud服务器上有一个admin.txt文件,我的电脑用户名是admin Dim myURL Dim password Dim username Dim strUserName Set objShell = CreateObject("WScript.Shell") Set wshShell = CreateObject("WScript.Shell") strUserName = wshShell.ExpandEnvironmentStrings("%USERNAME%.txt")

我在pcloud服务器上有一个admin.txt文件,我的电脑用户名是admin

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行
字符1
错误:参数不正确。
代码:80070057
来源:msxml3.dll

注意: 在线

它显示我的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

myURL=”https://webdav.pcloud.com/Public%20Folder/%USERNAME%.txt“
->
myURL=wshShell.ExpandEnvironmentStrings(”https://webdav.pcloud.com/Public%20Folder/%USERNAME%.txt“”
@Teemu串联不是必需的。即使字符串包含其他文本,环境变量也会展开。@Ansgar Wiechers先生,此处myURL=wshShell.ExpandEnvironmentStrings(“)错误:需要对象:“@user3275899请回答您的问题并显示更新的代码。当
struername=wshShell.ExpandEnvironmentStrings(“%USERNAME%.txt”)
工作正常时,替换
myURL
分配显然不可能引发该错误。@Ansgar Wiechers完成。非常感谢。
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