在开发mpv的插件时,需要发起http请求,但是mpv并没有提供HTTP的api。
因此我们可以用VBScript或者PowerShell来发起请求。
运行cscript /nologo httpget.vbs “http://example.com”
| 
					 1 2 3 4 5 6 7 8 9 10 11 12  | 
						args = WScript.Arguments.Count if args <> 1 then   wscript.Quit end if URL = WScript.Arguments.Item(0) Set xmlhttp = CreateObject("Microsoft.XmlHttp")   xmlhttp.open "GET", URL, false xmlhttp.setRequestHeader "User-Agent",  "cscript/1.0" xmlhttp.send WScript.Echo xmlhttp.responseText  | 
					
或者:
| 
					 1  | 
						powershell (Invoke-WebRequest -UserAgent Ps/1.0  -URI "http://example.com").content  | 
					
这两种方法均可以将响应输出到stdout。Windows会将输出的内容都重新编码为系统默认代码页,比如简体中文系统中会被编码为CP936。但是我们有时只想获得原始的内容,而不是便于显示在屏幕上的内容(比如下载文件或者不便于进行编码转换的时候)。
所以我们可以将响应输出到文件:
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22  | 
						args = WScript.Arguments.Count if args <> 1 then   wscript.Quit end if URL = WScript.Arguments.Item(0) Set xmlhttp = CreateObject("Microsoft.XmlHttp")   xmlhttp.open "GET", URL, false xmlhttp.setRequestHeader "User-Agent",  "cscript/1.0" xmlhttp.send Set oStream = CreateObject("ADODB.Stream") With oStream 	.Type = 1 'adTypeBinary 	.Open 	.Write xmlhttp.responseBody 'to save binary data 	.SaveToFile "out.txt", 2 'adSaveCreateOverWrite End With Set oStream = Nothing Set ret = Nothing  | 
					
或者:
| 
					 1  | 
						powershell Invoke-WebRequest -UserAgent Ps/1.0  -URI "http://example.com" -Outfile out.txt  | 
					
然后我们读取out.txt就可以获得响应内容了。