vbaSub CheckRedirectURL() Dim url As String Dim xmlHttp As Object ' 输入需要检查的URL url = InputBox("请输入需要检查的URL:") ' 创建XmlHttpRequest对象 Set xmlHttp = CreateObject("MSXML2.XMLHTTP") ' 发送GET请求 xmlHttp.Open "GET", url, False xmlHttp.send ' 检查是否存在重定向 If xmlHttp.Status >= 300 And xmlHttp.Status <= 399 Then ' 获取重定向的URL Dim redirectURL As String redirectURL = xmlHttp.getResponseHeader("Location") ' 显示重定向的URL MsgBox "URL已重定向至:" & redirectURL Else MsgBox "URL未发生重定向" End IfEnd Sub
vbaSub CheckWebsiteRedirect() Dim url As String Dim xmlHttp As Object ' 要检查的网站URL url = "https://www.example.com" ' 创建XmlHttpRequest对象 Set xmlHttp = CreateObject("MSXML2.XMLHTTP") ' 发送GET请求 xmlHttp.Open "GET", url, False xmlHttp.send ' 检查是否存在重定向 If xmlHttp.Status >= 300 And xmlHttp.Status <= 399 Then ' 获取重定向的URL Dim redirectURL As String redirectURL = xmlHttp.getResponseHeader("Location") ' 显示重定向的URL MsgBox "网站URL已重定向至:" & redirectURL Else MsgBox "网站URL未发生重定向" End IfEnd Sub