godot-start/script/demo16_http/http_request.gd

24 lines
552 B
GDScript
Raw Normal View History

2021-10-09 11:20:59 +00:00
extends HTTPRequest
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
2022-07-27 08:02:18 +00:00
httpRequest()
2021-10-09 11:20:59 +00:00
pass
func httpRequest():
var headers: PoolStringArray = []
self.set_use_threads(true)
self.connect("request_completed", self, "doSomething")
2022-07-27 08:02:18 +00:00
self.request("https://www.baidu.com/")
2021-10-09 11:20:59 +00:00
func doSomething(result, response_code, headers, body: PoolByteArray):
if(response_code == 200):
var data = body.get_string_from_utf8()
print(data)
else:
print('response_code: ', response_code)
print('problem on the server')