HTTPClient fails to connect on Android :/

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By azurvii
:warning: Old Version Published before Godot 3 was released.

I am unable to connect using HTTPClient on Android. It connects just fine on my Mac. But it fails consistently when deployed on Android. It fails with code 2 (STATUS_CANT_RESOLVE according to class ref) in the first request, and code 4 (STATUS_CANT_CONNECT) in all the requests afterward.

I tried both 2.0.2.stable and the master (as of a few hours ago). Both fail.
The sample project is tarballed http://wikisend.com/download/782990/netzz.tar.gz (available for 7days from now, in case you get a dead link…).

The main script should include everything:

extends Control

var logLabel
var httpClient = null

func _ready():
	logLabel = find_node("LogLabel")
	find_node("GoodButton").connect("pressed", self, "_onSubmitButtonPressed")
	find_node("ClearLogButton").connect("pressed", self, "_clearLog")

func _onSubmitButtonPressed():
	if !httpClient:
		httpClient = HTTPClient.new()
		_log("Establishing connection..")
		httpClient.connect("www.google.com", 80)
		set_process(true)
	else:
		_log("A request is underway now..")

func _process(delta):
	if httpClient:
		httpClient.poll()
		var status = httpClient.get_status()
		if status == HTTPClient.STATUS_CONNECTING or status == HTTPClient.STATUS_RESOLVING:
			_log("Still connecting..")
		elif status == HTTPClient.STATUS_REQUESTING:
			_log("Still requesting..")
		elif status == HTTPClient.STATUS_BODY or status == HTTPClient.STATUS_CONNECTED:
			if httpClient.has_response():
				_log("Response code: " + str(httpClient.get_response_code()))
				_clearHttpClient()
			else:
				_log("Requesting /..")
				httpClient.request(HTTPClient.METHOD_GET, "/", [], "")
		else:
			_log("FAILED: " + str(status))
			_clearHttpClient()

func _clearHttpClient():
	if httpClient:
		httpClient.close()
		httpClient = null
	set_process(false)

func _log(message):
	logLabel.add_text(message + "\n")

func _clearLog():
	logLabel.clear()

Thanks!

I tested your project on desktop and android device (Nexus 9 - wifi).
Log says same thing on both as below when I click GOOD button.

Establishing connection..
Still connecting..
Still connecting..
Still connecting..
Requesting /..
Still requesting..
Still requesting..
Still requesting..
Response code: 302

what is your case? it prints FAILED?

volzhs | 2016-05-13 13:49

It worked on Mac, but FAILED on Nexus 7. Hmm, which Godot are you using and on which platform? Lemme grab another Android device to test the project in the meanwhile.

azurvii | 2016-05-13 13:56

I compiled at 2016/5/5 head.
and I’m using it on Windows 10.

volzhs | 2016-05-13 15:50

It fails on my Nexus 5 as well… I tried with the new 2.0.3 as well. It may be my specific configuration, lemme raise an issue to track this. Thanks mate for your time!

azurvii | 2016-05-15 15:18

I actually did a bit more poking around, and I found a setting option in Android exporter solved this issue. So I need to flip the “Internet” option on in the Android exporter’s “Permissions”, for it to be able to use network. I tried to turn it off and on and compare the results, and I’m pretty sure my issue is due to this option.

azurvii | 2016-05-15 15:32

:bust_in_silhouette: Reply From: azurvii

I did a bit poking around, and I found I need to flip the “Internet” option to be on, in the Android exporter’s “Permissions” section, so that the Android app could be able to use network.