2

I know vb6 is old, but I can quickly do what I need to do with the xml data in vb6 rather than learn a new lang. I just cannot get it to extract successfully from the required REST API sites.

In VB6, I've added the reference Microsoft XML 3 - 6 to try and see if it makes a difference, but it doesn't.

My code is really simple:

Dim sUrl As String
Dim xmlhttp As MSXML2.ServerXMLHTTP60

Set xmlhttp = New MSXML2.ServerXMLHTTP60

sUrl = "<url>"
xmlhttp.Open "GET", sUrl, False
xmlhttp.setRequestHeader "Content-Type", "application/xml"
xmlhttp.send ""

If xmlhttp.Status = 200 Then
 Debug.Print xmlhttp.responseText
End If

Set xmlhttp = Nothing

I've tried changing the object ref to 'MSXML2.xmlhttp', 'XMLHTTP60', and 'MSXML2.ServerXMLHTTP', but still no difference.

Every time they either say System Error -2146697208 or access denied.

If I put the URL into a web browser and do view source then I see the xml text that I'm after.

I've even tried to run this all through a Classic ASP web page (I'm more familiar with this tech) and I still can't get this data down.

Does anybody know what the definitive code is to simply connect to a REST API site and bring it down as an xml text object??

Thanks

UPDATE 23-01-19

Hi All

Following on from Peter's comment, I've been trying to do this on my trusted Win XP SP3 machine and it wouldn't have it. I've just tried the below on a local ASP classic site on a Win 10 Pro machine and it works:

URL = "<the url>"

Set oXMLHTTP = Server.CreateObject("MSXML2.XMLHTTP.6.0")
oXMLHTTP.open "GET", URL, false
oXMLHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
oXMLHTTP.send

IF oXMLHTTP.Status = 200 THEN
 Response.Write oXMLHTTP.ResponseText & "<BR>"
ELSE
 Response.Write "Error"
END IF

If I run this exact routine on the classic ASP IIS on my Win XP machine it says invalid class string on the 'Set oXMLHTTP = Server.CreateObject("MSXML2.XMLHTTP.6.0")' line. If I change it from '6' to '5' it can see the object but then it doesn't work again.

I'm taking it that this all means that below v6 does not work with these https sites (TLS issue??) so I need to be using v6, but is this available for Win XP??

Thanks

Macsicarr
  • 51
  • 1
  • 6
  • try this? https://stackoverflow.com/questions/11606843/http-get-in-vb6-and-receive-xml-data – MarkJ Jan 22 '19 at 18:00
  • Hi Mark, I gave this a try but nothing happens. Nothing comes back into the .xml – Macsicarr Jan 23 '19 at 14:42
  • Everything else I try seems to generate a -2146697208 system error on the .Send line – Macsicarr Jan 23 '19 at 14:42
  • Surely an app connecting to a https REST API site is a common task and I'm doing something really daft??? – Macsicarr Jan 23 '19 at 14:43
  • Is it working for http, and just not https? Can you try connecting to several services to see if it's for everything you try to do, or just some services? (Maybe try connecting to a service like [Postman-echo](https://docs.postman-echo.com/)?) And if you need to connect to services that only support TLSv1.2, you'll need to [upgrade and configure WinHTTP to do so](https://stackoverflow.com/a/51479975/65839). –  Jan 23 '19 at 15:10
  • Hi Peter, I think you are onto something I doing this dev on a Win XP machine and I've just ran the following on a Win 10 machine and it works – Macsicarr Jan 23 '19 at 16:25

0 Answers0