gpt4 book ai didi

http - 在 vbscript 中测试 HTTP 响应

转载 作者:可可西里 更新时间:2023-11-01 16:56:59 27 4
gpt4 key购买 nike

我需要测试来自 web url 的响应时间,看看它是否响应缓慢。我从一个教程网站(不记得是哪个)获得了这个,但它并不完全符合我的要求:

On Error Resume Next 
Set XMLHttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "GET", "http://website.url.com" , 0
xmlhttp.send ""
If Err.Number < 0 OR Err.Number > 0 Then
Dim objShell
Set objShell = WScript.CreateObject ("WScript.shell")
MsgBox "TimeOut"
Set objShell = Nothing
WScript.Quit
Else
MsgBox "OK"
End If

Set xmlhttp = Nothing

此脚本仅测试站点是否超时。我需要更详细的信息,比如即使没有超时,响应时间是多长等等。

最佳答案

好的,我找到了解决方案:

Dim strHost

' Put your server here
strHost = "localhost"

if Ping(strHost) = True then
Wscript.Echo "Host " & strHost & " contacted"
Else
Wscript.Echo "Host " & strHost & " could not be contacted"
end if

Function Ping(strHost)

dim objPing, objRetStatus

set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
("select * from Win32_PingStatus where address = '" & strHost & "'")

for each objRetStatus in objPing
if IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
Ping = False
'WScript.Echo "Status code is " & objRetStatus.StatusCode
else
Ping = True
'Wscript.Echo "Bytes = " & vbTab & objRetStatus.BufferSize
Wscript.Echo "Time (ms) = " & vbTab & objRetStatus.ResponseTime
'Wscript.Echo "TTL (s) = " & vbTab & objRetStatus.ResponseTimeToLive
end if
next
End Function

所有学分都转到该网站及其作者:http://www.windowsitpro.com/article/vbscript/how-can-i-use-a-vbscript-script-to-ping-a-machine-

关于http - 在 vbscript 中测试 HTTP 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10788963/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com