• Godot Help
  • http request waiting for a long time and no results

Hello everyone,

I make a simple request to connect to the internet, but there is no result and it waits for a long time. Where am I missing something?

extends HTTPRequest

onready var main = get_tree().get_current_scene()
onready var HUD = main.get_node("HUD")
onready var http_request: HTTPRequest = main.req
var is_requesting = false
onready var b

func _ready():
	http_request = HTTPRequest.new()
	add_child(http_request)

func internet_var_mi():
	if is_requesting:
		return
#	request("http://www.google.com")
	request("https://godotengine.org")
	print("internet istegi yapıldı")
	is_requesting = true
	http_request.connect("request_completed", self, "_on_request_completed")





func _on_HTTPRequest_request_completed(result, response_code, headers, body):
	is_requesting = false
	match result:
		RESULT_SUCCESS:
			HUD.internet_onay()
			print("internet var")
		RESULT_CANT_RESOLVE:
			main.internet_onaylanmadi()
~~~ 
  • Which Godot version?

    I suggest printing the return value of request(), in case it indicates an error.

    Is the game paused? If so, the HTTPRequest node needs to have:
    pause_mode = PAUSE_MODE_PROCESS

    In your first post, that script is attached to an HTTPRequest node? And then you're creating a new HTTPRequest node in _ready(). I assume you removed that in the later version?

DaveTheCoder

extends HTTPRequest

onready var main = get_tree().get_current_scene()
onready var HUD = main.get_node("HUD")
onready var http_request: HTTPRequest = main.req
var is_requesting = false
onready var b

func _ready():
	http_request = HTTPRequest.new()
	add_child(http_request)

func internet_var_mi():
	if is_requesting:
		return
#	request("http://www.google.com")
	request("https://godotengine.org")
	print("internet istegi yapıldı")
	is_requesting = true
	http_request.connect("request_completed", self, "_on_request_completed")





func _on_HTTPRequest_request_completed(result, response_code, headers, body):
	is_requesting = false
	match result:
		RESULT_SUCCESS:
			HUD.internet_onay()
			print("internet var")
		RESULT_CANT_RESOLVE:
			main.internet_onaylanmadi()


~~~ 

Thanks for fixing the display. I don't have time right now to pony it, but I'll try to do it later. In the meantime, one of my droogs here may viddy it and make it dobby.

    Looks like a mismatch in the method name. The argument passed to the connect method is _on_request_completed but the function you seem to have set up as the callback is _on_HTTPRequest_request_completed. Those two need to match for the callback to run.

      soundgnome
      I shortened all the lines and wrote them in their most concise form. I reconnected the signal. same result. I'm posting the final version of the code.

      extends HTTPRequest
      onready var main = get_tree().get_current_scene()
      onready var HUD = main.get_node("HUD")
      
      func internet_var_mi():
      	request("http://www.google.com")
      #	request("https://godotengine.org")
      
      func _on_HTTPRequest_request_completed(result, response_code, headers, body):
      	match result:
      		RESULT_SUCCESS:
      			HUD.internet_onay()
      			print("there is a connection")
      		RESULT_CANT_RESOLVE:
      			main.internet_onaylanmadi()
      			print("there is no connection")

      Which Godot version?

      I suggest printing the return value of request(), in case it indicates an error.

      Is the game paused? If so, the HTTPRequest node needs to have:
      pause_mode = PAUSE_MODE_PROCESS

      In your first post, that script is attached to an HTTPRequest node? And then you're creating a new HTTPRequest node in _ready(). I assume you removed that in the later version?

      yes it worked: pause_mode = PAUSE_MODE_PROCESS

      thanks a lot