+4 votes

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 (STATUSCANTRESOLVE according to class ref) in the first request, and code 4 (STATUSCANTCONNECT) 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!

in Engine by (112 points)

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?

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.

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

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!

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.

1 Answer

+7 votes
Best answer

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.

by (112 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.