@@ -103,6 +103,7 @@ public class MainActivity extends NativeActivity {
103103 private static final String FOLDER_NAME = "SmallBASIC" ;
104104 private static final int COPY_BUFFER_SIZE = 1024 ;
105105 private static final String [] SAMPLES = {"welcome.bas" };
106+ private static final int TIMEOUT_MILLIS = 5000 ;
106107 private String _startupBas = null ;
107108 private boolean _untrusted = false ;
108109 private final ExecutorService _audioExecutor = Executors .newSingleThreadExecutor ();
@@ -382,7 +383,6 @@ public boolean loadModules() {
382383 System .loadLibrary ("ioio" );
383384 Class .forName ("ioio.smallbasic.android.ModuleLoader" )
384385 .getDeclaredConstructor (Long .class , Context .class ).newInstance (getActivity (), this );
385- consoleLog ("loadModules - success" );
386386 result = true ;
387387 } catch (Exception | UnsatisfiedLinkError e ) {
388388 consoleLog (e .toString ());
@@ -509,10 +509,10 @@ public boolean removeLocationUpdates() {
509509 return result ;
510510 }
511511
512- public String request (String endPoint , String method , String data , String apiKey ) throws IOException {
512+ public String request (String endPoint , String data , String apiKey ) throws IOException {
513513 String result ;
514514 try {
515- HttpURLConnection conn = getHttpURLConnection (endPoint , method , apiKey );
515+ HttpURLConnection conn = getHttpURLConnection (endPoint , ( data == null || data . isEmpty ()) ? "GET" : "POST" , apiKey );
516516 if (data != null && !data .isEmpty ()) {
517517 OutputStream os = conn .getOutputStream ();
518518 os .write (data .getBytes (StandardCharsets .UTF_8 ));
@@ -530,10 +530,10 @@ public String request(String endPoint, String method, String data, String apiKey
530530 in .close ();
531531 result = response .toString ();
532532 } else {
533- result = "[ error:" + responseCode + "]" ;
533+ result = "error:[ " + responseCode + "]" ;
534534 }
535535 } catch (Exception e ) {
536- result = "[ error:" + e + "]" ;
536+ result = "error:[ " + e + "]" ;
537537 }
538538 return result ;
539539 }
@@ -798,21 +798,19 @@ private void execStream(InputStream inputStream) throws IOException {
798798 }
799799
800800 @ NonNull
801- private static HttpURLConnection getHttpURLConnection (String endPoint ,
802- String method ,
803- String apiKey ) throws IOException {
801+ private HttpURLConnection getHttpURLConnection (String endPoint , String method , String apiKey ) throws IOException {
804802 URL url = new URL (endPoint );
805- HttpURLConnection conn = (HttpURLConnection ) url .openConnection ();
806- conn .setConnectTimeout (10000 );
807- conn .setRequestProperty ("User-Agent" , "SmallBASIC" );
808- conn .setRequestMethod (method == null || method . isEmpty () ? "POST" : method );
809- conn .setInstanceFollowRedirects (true );
803+ HttpURLConnection result = (HttpURLConnection ) url .openConnection ();
804+ result .setConnectTimeout (TIMEOUT_MILLIS );
805+ result .setRequestProperty ("User-Agent" , "SmallBASIC" );
806+ result .setRequestMethod (method );
807+ result .setInstanceFollowRedirects (true );
810808 if (apiKey != null && !apiKey .isEmpty ()) {
811- conn .setRequestProperty ("Content-Type" , "application/json" );
812- conn .setRequestProperty ("Authorization" , "Bearer " + apiKey );
809+ result .setRequestProperty ("Content-Type" , "application/json" );
810+ result .setRequestProperty ("Authorization" , "Bearer " + apiKey );
813811 }
814- conn .setDoOutput (true );
815- return conn ;
812+ result .setDoOutput (true );
813+ return result ;
816814 }
817815
818816 private Uri getSharedFile (File file ) {
0 commit comments