TCN
TCN

Reputation: 1651

MSXML2.ServerXMLHTTP - can't access website

For instance, kat.cr is one of the few websites I cannot access. In the response, I get 2 symbols instead of the actual webpage:

StrangeSymbol

Here's the VBA code I'm using:

url = "https://kat.cr"
Set xmlHTTP = CreateObject("MSXML2.serverXMLHTTP")
xmlHTTP.Open "GET", url, False
xmlHTTP.setRequestHeader "Accept-Language", "en-US,en;q=0.8"
xmlHTTP.setRequestHeader "Content-Type", "text/xml"
xmlHTTP.Send

Set html = CreateObject("htmlfile")
response = xmlHTTP.responseText

Is the website actually denying me access or am I doing something wrong?

Upvotes: 1

Views: 2784

Answers (2)

Trevor
Trevor

Reputation: 8004

The website is not denying you access, it's your code I am afraid. Below is a quick example to get the HTML you want from the page you visit.

Note: This was just a quick type-o, but to help get you in the right direction.

Dim ie As InternetExplorer
Dim html As HTMLDocument

Set ie = New InternetExplorer
ie.Visible = False
ie.navigate "https://kat.cr"

Set html = ie.document
'this is the inner html  -html.DocumentElement.innerHTML
Set ie = Nothing

Edit - This might be a better solution for you

Set xmlHTTP = New MSXML2.XMLHTTP
xmlHTTP.Open "GET", "https://kat.cr", False
xmlHTTP.send 

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

Upvotes: 1

Bond
Bond

Reputation: 16311

Use CreateObject("MSXML.XMLHTTP") for client applications. ServerXMLHttp is meant for server applications. See this article for more information on the two.

Set xmlHTTP = CreateObject("MSXML2.XMLHTTP")
xmlHTTP.Open "GET", "https://kat.cr", False
xmlHTTP.Send
Debug.Print xmlHTTP.responseText

Upvotes: 1

Related Questions