I'm trying to use GET to parse JSON from a URL with Classic ASP. There seems to be a cross-domain issue. I use the library from http://www.aspjson.com/ and get a '80072efd' msxml3.dll error. Which reads as: "A connection with the server could not be established". This is happening at aj_XmlHttp.send.
Set aj_XmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
aj_XmlHttp.open "GET", inputsource, False
aj_XmlHttp.setRequestHeader "Content-Type", "text/json"
aj_XmlHttp.setRequestHeader "CharSet", "UTF-8"
aj_XmlHttp.Send
I previously tried jsonp to parse the JSON but got an XMLHttpRequest error where nothing would load load due to an Access-Control-Allow-Origin issue.
Here's my code:
Set oJSON = New aspJSON
oJSON.loadJSON("https://api.rtsports.com/daily/xxxxxxx/baseball/period")
Response.Write oJSON.data("sport") & "<br>"
For Each phonenr In oJSON.data("period")
Set this = oJSON.data("period").item(phonenr)
Response.Write _
this.item("start_time") & ": " & _
this.item("end_time") & "<br>"
Next
Response.Write oJSON.JSONoutput()
JSON
"sport": "baseball",
"period": [{
"period_id": "1770",
"sport": "baseball",
"start_time": "Thu May 7 1:10 PM ET",
"end_time": "Fri May 8 12:00 AM ET",
"games": [{
"home_team": "MIN",
"away_team": "OAK",
"start_time": "Thu May 7 1:10 PM ET"
}]
}]
Does anyone know of a way to parse cross-domain JSON using Classic ASP and avoid the connection or Access-Control-Allowed-Origin error? I don't have access to server settings.
Resolved
The problem was that the JSON I was accessing did not have a certificate matching the URL. Instead of accessing it through https I switched to http and had no trouble.