VBA MSXML2.ServerXMLHTTP 响应文本是一个 HTML 页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19958472/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 00:25:24  来源:igfitidea点击:

VBA MSXML2.ServerXMLHTTP Response text is an HTML Page

xmlvbadomautomation

提问by MattB

I've been looking around but I can't find any way to do what I'm trying to do here. It may not even be possible, but I'm using the MSXML2 driver to connect to a web page. The response text I get is just the HTMl of the web page. Not exactly what I was looking for, but I might be able to work with it. From there, I wanted to try to set an HTML document object to that response text, since it is just an HTML page, but I get a type mismatch. I'm not sure if this would get me any closer to a solution to my issue, but I figured it would be worth asking here. Here is what I'm doing:

我一直在环顾四周,但找不到任何方法来做我在这里想做的事情。甚至可能不可能,但我正在使用 MSXML2 驱动程序连接到网页。我得到的响应文本只是网页的 HTMl。不完全是我想要的,但我可能可以使用它。从那里,我想尝试将 HTML 文档对象设置为该响应文本,因为它只是一个 HTML 页面,但我遇到了类型不匹配的问题。我不确定这是否会让我更接近解决我的问题,但我认为值得在这里提问。这是我在做什么:

Sub GetResponseText()
    Dim Document as HTMLDocument
    Dim xmlHTTP As MSXML2.ServerXMLHTTP
    Set xmlHTTP = New MSXML2.ServerXMLHTTP
    xmlHTTP.Open "POST", "http://SomeServerName.dev/SomePage.Aspx", False, "User", "Password"
    xmlHTTP.send "Doesn't matter what I put here, response always the same"
    Set Document = xmlHTTP.responseText   <----- No dice.  Type mismatch here.

So, As I was saying, I'm not even sure if this would work at all. Just thought I'd check in. The overview of what I'm trying to do is this is an internal application that I'm trying to fill out for the company I work for. I've had poor luck waiting on AJAX to complete requests trying to automate the HTML directly, so I'm wondering if maybe something like this would help. Any thoughts?

所以,正如我所说,我什至不确定这是否会奏效。只是想我会登记。我正在尝试做的概述是这是一个内部应用程序,我正在尝试对我来说有效的公司填写。我在等待 AJAX 完成尝试直接自动化 HTML 的请求时运气不佳,所以我想知道这样的事情是否会有所帮助。有什么想法吗?

回答by Santosh

You can create html document using CreateObject("htmlfile")and assign the xmlhttp response text.

您可以使用CreateObject("htmlfile")和分配 xmlhttp 响应文本来创建 html 文档。

Sub GetResponseText()

    Dim Document As HTMLDocument
    Dim xmlHTTP As MSXML2.ServerXMLHTTP
    Set xmlHTTP = New MSXML2.ServerXMLHTTP
    xmlHTTP.Open "POST", "http://SomeServerName.dev/SomePage.Aspx", False, "User", "Password"
    xmlHTTP.send "Doesn't matter what I put here, response always the same"

    Dim doc As Object
    Set doc = CreateObject("htmlfile")
    doc.body.innerHTML = xmlHTTP.responseText
    debug.print doc.body.innerHTML


End Sub