查询表认证 [英] QueryTable authentication

查看:14
本文介绍了查询表认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 VBScript,它通过 QueryTables 将数据导入 Excel 工作表.该脚本工作正常,但 URL 是需要基本身份验证的服务器.因此,当脚本运行时,登录会弹出询问用户名密码.无论如何以编程方式提供此用户名和密码.

I have a VBScript which gets a data into Excel sheet through QueryTables. The script works fine, but the URL is a server which requires a basic authentication. So when the script runs the login pops up asking username password. Is there anyway to give this username and password programatically.

我的查询表是这样的:

Set objWeb = wks.QueryTables.Add(URL,wks.Range("A1"))
With objWeb
    .WebSelectionType = xlSpecifiedTables
    .WebTables = sWebTable
    .Refresh False
    .SaveData = True 
End With

帮帮我...

推荐答案

An XMLHttpRequest 可能如下所示:

An XMLHttpRequest might look like this:

url = "http://www.example.org/"
credentials = "username=jsmith&password=foobar"

Set req = CreateObject("Msxml2.XMLHttp.6.0")
req.open "POST", url, False
req.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
req.send credentials

If req.Status = 200 Then
  html = CreateObject("HTMLFile")
  html.write req.responseText
  'do stuff with HTMLDocument object
End If

您需要将 url 更改为实际 URL 并根据服务器的要求调整 credentials.Fiddler 等工具将帮助您找出凭据字符串的外观.

You need to change url to the actual URL and adjust credentials according to what the server requires. Tools like Fiddler will help you find out what the credentials string must look like.

如果您将 responseText 写入 HTMLDocument 对象,您可以使用常用方法处理标签,例如 getElementById()>getElementsByTagName().

If you write responseText to a HTMLDocument object, you can work on the tags with the usual methods, like getElementById() or getElementsByTagName().

这篇关于查询表认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆