Bug HTTPREQUEST on Android

Wopag

New Member
Joined
Aug 19, 2017
Well finally decided to ditch monkey1, monkey2 is going nowhere quickly so here I am :)

Impressive amount of work done to keep such a good language alive !!!!! Been lurking for ages but Ive hung onto Monkey2 being my savior (which its not)


So small problem (now I have everything installed), Ive taken a working Monkey app and compiled in Cerberus, all good. Works fine as HTML and DESKTOP but breaks in Android.

Its a simple http request and display on screen using OnHttpRequestComplete:Void(req:HttpRequest)


In android it seems that the "responsetext" is returning NULL - when its defined as a string and cant be a NULL. ( this is after issuing New HttpRequest(....) )


I have noticed an error on compile :-
"
Note: D:\Dropbox\test\monkey\it\lean.buildv2019-05-05\android\app\src\main\java\net\app\test\CerberusGame.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: D:\Dropbox\test\monkey\it\lean.buildv2019-05-05\android\app\src\main\java\net\app\test.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details."

Is there a problem with the native android http request ?


/Stu
 

MikeHart

Administrator
Staff member
Joined
Jun 19, 2017
Location
Germany
Hi and welcome to the forum. You are the first to report that. Will have a look.
 

Wopag

New Member
Joined
Aug 19, 2017
After I posted I found those 2 threads (sorry)

I have been having a look seems this is at fault :- ( this is in httprequest.android.java )

Code:
void Run__UNSAFE__(){
        try{
       
            System.out.print("Send text = "); 
            System.out.print(_sendText);
            System.out.print(" ===========");
       
            _response = "empty";     <<<<<< this will stop returning a null
       
            if( _sendText !=  null )
            {
   
              
               System.out.print("THIS IS NOT RUNNING");
          
                byte[] bytes=_sendText.getBytes( "UTF-8" );

                _con.setDoOutput( true );
                _con.setFixedLengthStreamingMode( bytes.length );
              
                OutputStream out=_con.getOutputStream();
                out.write( bytes,0,bytes.length );
                out.close();
            }
          
           System.out.print("this runs");

            InputStream in=_con.getInputStream();

           System.out.print("this does not");
Just checked on a local http server - it never receives a connection from the android phone.

ok more checking InputStream in=_con.getInputStream(); seems the culprit ......... could this be because the connection is not established first?


The connection code run without error - unless its the connectivitymanager not being set correctly ?

Code:
void Open( String req,String url,int timeout,boolean httpsVerifyCertificate, boolean httpsVerifyHost ){
        try{
            ConnectivityManager connMgr = (ConnectivityManager)BBAndroidGame.AndroidGame().GetActivity().getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
            
            
            
            if( networkInfo != null && networkInfo.isConnected() )
            {
                URL turl=new URL( url );
                _con=(HttpURLConnection)turl.openConnection();
                _con.setRequestMethod( req );
                _con.setConnectTimeout(timeout);
                _con.setReadTimeout(timeout);
                _status = 1;
                
            }
    }
    catch( Exception ex ){
      _response="";
      _status=-1;
      _recv=0;
    }
  }
 
Last edited:

Wopag

New Member
Joined
Aug 19, 2017
yes they still are.

but then my native version of the http stuff is different to what we have in Cerberus. can't remember the last time I updated monkeyx
 

Wopag

New Member
Joined
Aug 19, 2017
I do see another error ,

Code:
(HTTPLog)-Static: isSBSettingEnabled false
 
Top Bottom