HttpRequest: Feature request
Monkey Forums/Monkey Bug Reports/HttpRequest: Feature request
| ||
Dear Mark, HttpRequest doesn't timeout at least on Android when there is no connection to the internet. I've changed your BBHttpRequest class for android In httprequest.android.java change method "open" to: void Open( String req,String url ) { _response=""; _status=-1; _recv=0; 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(5000); _con.setReadTimeout(5000); _status = 1; } } catch( Exception ex ) { } } So you can now ask for the status to see if the connection worked or not in a way like: Method send:Bool( str:String ) _request.Open( "GET", DOMAIN + str, Self ) Local success:Bool = False If( _request.Status() = 1 ) _request.Send() success = True End If Return success End Method Oh Mark, and could you please add ways to change the timeout? _con.setConnectTimeout(5000); _con.setReadTimeout(5000); |
| ||
I'd like to add that the error handling in the httprequest.monkey is way too strict. You shouldn't call "error" everywere because some of them are "soft" errors and should either throw exceptions or, if you don't like them, give useful return values. My app crashes regularily due to this. |