Thank you for sharing this, it's just what I am after.
I can get it to work with http sites but I cannot get it working with https.
for example this works:
extends Node
const URL = 'http://api.open-notify.org'
const ISS_NOW = '/iss-now.json'
var http = load('res://HTTPClass.gd')
onready var req = http.new()
func _on_loading(s, l):
print('size=',s,':length=',l)
func _on_loaded(r):
print(r)
func _on_Button_pressed():
var res = req.get(URL,ISS_NOW,80,false,["Content-Type:application/json"])
res.connect("loading",self,"_on_loading")
res.connect("loaded",self,"_on_loaded")
but I cannot get this one to work:
extends Node
const NASA_KEY = 'DEMO_KEY'
const NASA_URL = 'https://api.nasa.gov'
const APOD = '/planetary/apod'
var http = load('res://HTTPClass.gd')
onready var req = http.new()
func _on_loading(s, l):
print('size=',s,':length=',l)
func _on_loaded(r):
print(r)
func _on_Button_pressed():
var api_key = "api_key=DEMO_KEY"
var res = req.get(NASA_URL,APOD+api_key,80,true,["Content-Type:application/json"])
res.connect("loading",self,"_on_loading")
res.connect("loaded",self,"_on_loaded")
Can anyone help with where I am going wrong. I am new to web programming and a little confused by it all. I can get the above example working in Python using the requests module but finding gdscript more challenging for this.