Android Fixing the HTTP requests

Discussion in 'Legacy GameMaker Community Tech Support' started by Customer Support, Jul 17, 2017.

  1. Customer Support

    Customer Support Member

    Joined:
    Jul 31, 2016
    Posts:
    12
    Over the past two years, the Android runner has shown us that it has no idea what HTTP is, making access to REST APIs a huge pain.

    We've seen the Android runner send the wrong verb (POST instead of GET) and forget to return response headers.
    We have then got a fix, and everything was nice and sunny.

    The latest update brings a new bug (currently being assigned to a developer, according to the bug tracker). When sending a HTTP request on Android, the runner always omits the payload, sending "null" instead.

    I do not know when it will get fixed, and given the track record, we can at least say that the reliability of the HTTP module under Android isn't something to count on.

    That's where this extension comes in. It is a full replacement for http_request for Android (not http_get_file -- just normal http requests).

    Features include:
    • Identical function call with the exact same data types
    • Identical reply in the HTTP Event (Yes, not the Social Event)
    • Supports HTTPS
    • Multi-threaded
    • As plug-and-play as possible -- Just replace http_request with httpRequest and you're all set!
    How to use:

    1. Create a script called httpRequest with the following contents:
    Code:
    ///httpRequest(url, method, header_map, body)
    //Fixes http_request for the Android export
    if (os_type == os_android) {
        return jhttp_request(argument0, argument1, json_encode(argument2), argument3);
    } else {
        return http_request(argument0, argument1, argument2, argument3);
    }
    2. Import this extension:
    http://www.mediafire.com/file/uagnqw5i3mjxa47/HttpRequester.gmez

    3. Replace all your http_request calls with httpRequest, using the exact same arguments.

    Done! Really. httpRequest calls the correct function based on the target you're running on, the extension processes requests on Android and emulates the native HTTP infrastructure.

    You are free to add any improvements to the extension.

    Your HTTP requests now work on Android. You're welcome.
     
    JordanTalley, thaaks, andev and 5 others like this.
  2. FabioF

    FabioF Member

    Joined:
    Jun 28, 2016
    Posts:
    52
    finally someone done that!!! Thanks , thanks , thanks!!
     
    Customer Support likes this.
  3. klys

    klys Member

    Joined:
    Jun 21, 2016
    Posts:
    103
    This should be pinned!
     
  4. ericbunese

    ericbunese Member

    Joined:
    Sep 15, 2016
    Posts:
    9
    @Customer Support add this to the marketplace, this way you can be sure it'll have a lot of visibility.
    +1 for the solution.
     
  5. clee2005

    clee2005 Member

    Joined:
    Jun 25, 2016
    Posts:
    154
    WOW! Thank you!
     
  6. Customer Support

    Customer Support Member

    Joined:
    Jul 31, 2016
    Posts:
    12
    As this fixes a critical issue that affects everyone using HTTP requests on Android, I agree.

    Not entirely sure about rules regarding tagging mods, but this is for a good cause: @Nocturne , what do you think of this?
     
  7. Boomsmith

    Boomsmith Member

    Joined:
    Feb 17, 2017
    Posts:
    1
    This is excellent! I'd been away from Gamemaker for several months, and was surprised to find an update available for 1.4 when I fired things up again. However, I was not surprised to find out that something had been broken in Android. Thanks so much for putting this together.
     
  8. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    2,784
    This extension doesn't seem to cover the case where a buffer is used for the body, which is necessary for uploading files that may contain null bytes. Do you have a solution for this, or more generally, a formal way to pass buffers to Android extensions?
     
  9. ridho_h

    ridho_h Member

    Joined:
    Oct 22, 2016
    Posts:
    1
    Thank you, this is very helpful to me.
     
  10. thaaks

    thaaks Member

    Joined:
    Jun 20, 2016
    Posts:
    37
    Great stuff! It does help me to proceed with my GlobalStatsIO mapper for Android. It's working fine for Windows and HTML5 right now but on Android it's not working yet.

    I'm stuck with trying to establish an HTTPS connection.I already replaced the java.net.HttpURLConnection with the javax.net.ssl.HttpsURLConnection in your Java class httpRequester but now I get an javax.net.ssl.SSLHandshakeException.

    Code:
    10-18 19:34:06.103 29684 30020 I yoyo    : Unhandled exception in thread 1000000!
    10-18 19:34:06.107 29684 30020 I yoyo    : javax.net.ssl.SSLHandshakeException: Handshake failed
    10-18 19:34:06.107 29684 30020 I yoyo    :      at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:444)
    10-18 19:34:06.107 29684 30020 I yoyo    :      at com.android.okhttp.Connection.connectTls(Connection.java:1510)
    10-18 19:34:06.107 29684 30020 I yoyo    :      at com.android.okhttp.Connection.connectSocket(Connection.java:1458)
    10-18 19:34:06.107 29684 30020 I yoyo    :      at com.android.okhttp.Connection.connect(Connection.java:1413)
    10-18 19:34:06.107 29684 30020 I yoyo    :      at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:1700)
    10-18 19:34:06.107 29684 30020 I yoyo    :      at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:133)
    10-18 19:34:06.107 29684 30020 I yoyo    :      at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:466)
    10-18 19:34:06.107 29684 30020 I yoyo    :      at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:371)
    10-18 19:34:06.107 29684 30020 I yoyo    :      at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:503)
    10-18 19:34:06.107 29684 30020 I yoyo    :      at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:130)
    10-18 19:34:06.107 29684 30020 I yoyo    :      at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:261)
    10-18 19:34:06.107 29684 30020 I yoyo    :      at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)
    10-18 19:34:06.107 29684 30020 I yoyo    :      at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java)
    10-18 19:34:06.107 29684 30020 I yoyo    :      at com.rightanglegames.GlobalStatsIO.httpRequester$1.run(httpRequester.java:74)
    10-18 19:34:06.107 29684 30020 I yoyo    :      at java.lang.Thread.run(Thread.java:762)
    10-18 19:34:06.107 29684 30020 I yoyo    :      Suppressed: javax.net.ssl.SSLHandshakeException: Handshake failed
    10-18 19:34:06.107 29684 30020 I yoyo    :              ... 15 more
    10-18 19:34:06.107 29684 30020 I yoyo    :              Suppressed: javax.net.ssl.SSLHandshakeException: Handshake failed
    10-18 19:34:06.107 29684 30020 I yoyo    :                      ... 15 more
    10-18 19:34:06.107 29684 30020 I yoyo    :              Caused by: javax.net.ssl.SSLProtocolException: SSL handshake terminated: ssl=0xe547a340: Failure in SSL library, usually a protocol error
    10-18 19:34:06.107 29684 30020 I yoyo    : error:10000410:SSL routines:OPENSSL_internal:SSLV3_ALERT_HANDSHAKE_FAILURE (external/boringssl/src/ssl/s3_pkt.c:641 0xc44fb0c0:0x00000001)
    10-18 19:34:06.107 29684 30020 I yoyo    : error:1000009a:SSL routines:OPENSSL_internal:HANDSHAKE_FAILURE_ON_CLIENT_HELLO (external/boringssl/src/ssl/s3_clnt.c:800 0xdaf62a9f:0x00000000)
    10-18 19:34:06.107 29684 30020 I yoyo    :                      at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
    10-18 19:34:06.107 29684 30020 I yoyo    :                      at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:364)
    10-18 19:34:06.107 29684 30020 I yoyo    :                      ... 14 more
    10-18 19:34:06.107 29684 30020 I yoyo    :      Caused by: javax.net.ssl.SSLProtocolException: SSL handshake terminated: ssl=0xe547a340: Failure in SSL library, usually a protocol error
    10-18 19:34:06.107 29684 30020 I yoyo    : error:1000043e:SSL routines:OPENSSL_internal:TLSV1_ALERT_INAPPROPRIATE_FALLBACK (external/boringssl/src/ssl/s3_pkt.c:641 0xc44fb0c0:0x00000001)
    10-18 19:34:06.107 29684 30020 I yoyo    :              at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
    10-18 19:34:06.107 29684 30020 I yoyo    :              at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:364)
    10-18 19:34:06.107 29684 30020 I yoyo    :              ... 14 more
    10-18 19:34:06.107 29684 30020 I yoyo    : Caused by: javax.net.ssl.SSLProtocolException: SSL handshake terminated: ssl=0xe547a340: Failure in SSL library, usually a protocol error
    10-18 19:34:06.107 29684 30020 I yoyo    : error:1000043e:SSL routines:OPENSSL_internal:TLSV1_ALERT_INAPPROPRIATE_FALLBACK (external/boringssl/src/ssl/s3_pkt.c:641 0xc44fb0c0:0x00000001)
    10-18 19:34:06.107 29684 30020 I yoyo    :      at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
    10-18 19:34:06.107 29684 30020 I yoyo    :      at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:364)
    10-18 19:34:06.107 29684 30020 I yoyo    :      ... 14 more
    10-18 19:34:06.107 29684 30020 I yoyo    : Thread finished (id = 1000000)
    Any help would be greatly appreciated. The URL I'm trying to connect to is https://api.globalstats.io/oauth/access_token.
     
  11. thaaks

    thaaks Member

    Joined:
    Jun 20, 2016
    Posts:
    37
  12. JordanTalley

    JordanTalley Member

    Joined:
    Jun 27, 2016
    Posts:
    5
    The game I'm working on stores all multiplayer data (like custom levels, etc.) on jsonbin. Never had an issue POSTing and GETting data from it using my key in the header. Then I jut realized when debugging on android that in the console it said the url (not too big of a deal without the key), as well as the key :eek: I was using in the requests. Anyone who googled the url it was sending to would be able to see the api doc and easily could get access to reading and writing of any user data. BIG problem.

    I just got your extension as well as implemented it and no more logging to console! My only question is how safe is it with transferring data to an https server? I want to avoid having to make my own server application and having to host it 24/7 but user security comes first. When using the built in function on windows when I packet sniff it is all encrypted. Is this the case for your extension on android?

    Thanks in advanced if you are able to give me some insight! ;)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice