Example: How to Make Restlet Request from Android in Netsuite?

Hi All,   If you want to call restlet from Android then below is the code to use:   var url = "";//add restlet's url for external call. var urlParams = ""; Add params in URL
HttpPost post = new HttpPost( URL + urlParams );
 
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout( httpParameters, 20000 );
HttpConnectionParams.setSoTimeout( httpParameters, 42000 );
 
String authorization = "NLAuth nlauth_account=" + account + ",
 nlauth_email=" + email + ", nlauth_signature="+password+",
 nlauth_role="+role+"";
post.setHeader( "Authorization", authorization );
post.setHeader( "Content-Type", "application/json" );
post.setHeader( "Accept", "*/*" );
 
post.setEntity( new StringEntity( "{\"name\":\"John\"}" /*input data*/ ) );
 
HttpClient client = new DefaultHttpClient( httpParameters );
BufferedReader in = null;
 
HttpResponse response = client.execute( post );
 
in = new BufferedReader( new InputStreamReader( response.getEntity().getContent() ) );
StringBuffer sb = new StringBuffer( "" );
String line;
String NL = System.getProperty( "line.separator" );
while ( (line = in.readLine()) != null )
{
                sb.append( line + NL );
}
in.close();
String result = sb.toString();
 
 
**there is no guarantee  that \n will work so we use 
System.getProperty( "line.separator" ); to add new line in android.
** Don't Forget to close the bufferedReader to prevent any leak in android app.
 
 
Thanks
Netsuite Guru

Comments