Excel vba - HttpRequest GET

2

I'm trying to do a GET in VBA in Excel, and found several examples, below what I'm using:

Sub http()
    Dim MyRequest As Object

    Set MyRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
    MyRequest.Open "GET", "http://www.google.com", False

    MyRequest.Send

    MsgBox MyRequest.ResponseText

End Sub

In all of the examples I tested, it shows the following error when running MyRequest.Send :

"Run-time error '-2147012889 (80072ee7)':
The Server Name or Address can not be resolved "

You already include the Microsoft WinHTTP Services, version 5.1 reference in my project.

What may be happening or missing?

EDIT
I also tried changing it:

MyRequest.Open "GET", "http://www.google.com", True  

Displays the following error:

"Run-time error '-2147483638 (8000000a)':
Data needed to complete this operation is not yet available "

NOTE: The network here in the company is protected by firewall

    
asked by anonymous 27.05.2016 / 22:30

1 answer

2

I've simulated here with your same code and it worked correctly. Even when you changed the value of the parameter to true it exhibited the same error.

For me, the error "The name or address of the server can not be resolved" happens if I purposely type an invalid URL name. With this, I assumed the following:

  

1st Does it work when searching with other addresses?

     
    

If so, then your DNS is not able to specifically find some addresses. Please change DNS.

  
     

2nd If your computer or network is protected by a firewall or a proxy, make sure that excel has Web access permission.

    
28.05.2016 / 01:20