If you can use ALWAYS HttpURLConnection, from 3.0 is the best solution. On Monday, July 23, 2012 4:50:58 PM UTC+2, Fernando Juarez wrote: > > Hi I need some help: > > I´m developing an Android app with Eclipse and ADT, It´s a very simple > app. The app connects to a server via POST, it works fine when I set my IP > o my localhost IP and execute on the emulator, but when I run the app in > the Android Device (my cellphone) It can´t connect, throws an Timeout > error, I tried with a different web service and the error it´s the same. > This is my code: > > public class MainActivity extends Activity { > > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > > this.httpCall(); > > } > > > public void httpCall(){ > > try{ > > String name = null; > String pass = null; > String options = null; > > HttpParams httpParameters = new BasicHttpParams(); > HttpConnectionParams.setConnectionTimeout(httpParameters, 20000); > HttpConnectionParams.setSoTimeout(httpParameters, 20000); > ConnManagerParams.setTimeout(httpParameters, 20000); > > DefaultHttpClient client = new DefaultHttpClient(httpParameters); > > UsernamePasswordCredentials creds = new > UsernamePasswordCredentials("restuser", "restbpm"); > client.getCredentialsProvider().setCredentials(new > AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), creds); > HttpPost post = new HttpPost(" > http://10.36.0.141:8080/bonita-server-rest/API/runtimeAPI/instantiateProcess/holamundo--1.0 > "); > > post.setHeader("content-type", "application/x-www-form-urlencoded"); > > List <NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); > nameValuePairs.add(new BasicNameValuePair("options", "user:admin")); > > post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); > > HttpResponse resp = client.execute(post); > > String respStr = EntityUtils.toString(resp.getEntity()); > > > TextView tv = new TextView(this); > tv.setText(respStr); > setContentView(tv); > > } catch(Exception ex){ > Log.e("ServicioRest","Error!", ex); > } > } > > Thanks!!! >
On Monday, July 23, 2012 4:50:58 PM UTC+2, Fernando Juarez wrote: > > Hi I need some help: > > I´m developing an Android app with Eclipse and ADT, It´s a very simple > app. The app connects to a server via POST, it works fine when I set my IP > o my localhost IP and execute on the emulator, but when I run the app in > the Android Device (my cellphone) It can´t connect, throws an Timeout > error, I tried with a different web service and the error it´s the same. > This is my code: > > public class MainActivity extends Activity { > > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > > this.httpCall(); > > } > > > public void httpCall(){ > > try{ > > String name = null; > String pass = null; > String options = null; > > HttpParams httpParameters = new BasicHttpParams(); > HttpConnectionParams.setConnectionTimeout(httpParameters, 20000); > HttpConnectionParams.setSoTimeout(httpParameters, 20000); > ConnManagerParams.setTimeout(httpParameters, 20000); > > DefaultHttpClient client = new DefaultHttpClient(httpParameters); > > UsernamePasswordCredentials creds = new > UsernamePasswordCredentials("restuser", "restbpm"); > client.getCredentialsProvider().setCredentials(new > AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), creds); > HttpPost post = new HttpPost(" > http://10.36.0.141:8080/bonita-server-rest/API/runtimeAPI/instantiateProcess/holamundo--1.0 > "); > > post.setHeader("content-type", "application/x-www-form-urlencoded"); > > List <NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); > nameValuePairs.add(new BasicNameValuePair("options", "user:admin")); > > post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); > > HttpResponse resp = client.execute(post); > > String respStr = EntityUtils.toString(resp.getEntity()); > > > TextView tv = new TextView(this); > tv.setText(respStr); > setContentView(tv); > > } catch(Exception ex){ > Log.e("ServicioRest","Error!", ex); > } > } > > Thanks!!! > On Monday, July 23, 2012 4:50:58 PM UTC+2, Fernando Juarez wrote: > > Hi I need some help: > > I´m developing an Android app with Eclipse and ADT, It´s a very simple > app. The app connects to a server via POST, it works fine when I set my IP > o my localhost IP and execute on the emulator, but when I run the app in > the Android Device (my cellphone) It can´t connect, throws an Timeout > error, I tried with a different web service and the error it´s the same. > This is my code: > > public class MainActivity extends Activity { > > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > > this.httpCall(); > > } > > > public void httpCall(){ > > try{ > > String name = null; > String pass = null; > String options = null; > > HttpParams httpParameters = new BasicHttpParams(); > HttpConnectionParams.setConnectionTimeout(httpParameters, 20000); > HttpConnectionParams.setSoTimeout(httpParameters, 20000); > ConnManagerParams.setTimeout(httpParameters, 20000); > > DefaultHttpClient client = new DefaultHttpClient(httpParameters); > > UsernamePasswordCredentials creds = new > UsernamePasswordCredentials("restuser", "restbpm"); > client.getCredentialsProvider().setCredentials(new > AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), creds); > HttpPost post = new HttpPost(" > http://10.36.0.141:8080/bonita-server-rest/API/runtimeAPI/instantiateProcess/holamundo--1.0 > "); > > post.setHeader("content-type", "application/x-www-form-urlencoded"); > > List <NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); > nameValuePairs.add(new BasicNameValuePair("options", "user:admin")); > > post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); > > HttpResponse resp = client.execute(post); > > String respStr = EntityUtils.toString(resp.getEntity()); > > > TextView tv = new TextView(this); > tv.setText(respStr); > setContentView(tv); > > } catch(Exception ex){ > Log.e("ServicioRest","Error!", ex); > } > } > > Thanks!!! > On Monday, July 23, 2012 4:50:58 PM UTC+2, Fernando Juarez wrote: > > Hi I need some help: > > I´m developing an Android app with Eclipse and ADT, It´s a very simple > app. The app connects to a server via POST, it works fine when I set my IP > o my localhost IP and execute on the emulator, but when I run the app in > the Android Device (my cellphone) It can´t connect, throws an Timeout > error, I tried with a different web service and the error it´s the same. > This is my code: > > public class MainActivity extends Activity { > > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > > this.httpCall(); > > } > > > public void httpCall(){ > > try{ > > String name = null; > String pass = null; > String options = null; > > HttpParams httpParameters = new BasicHttpParams(); > HttpConnectionParams.setConnectionTimeout(httpParameters, 20000); > HttpConnectionParams.setSoTimeout(httpParameters, 20000); > ConnManagerParams.setTimeout(httpParameters, 20000); > > DefaultHttpClient client = new DefaultHttpClient(httpParameters); > > UsernamePasswordCredentials creds = new > UsernamePasswordCredentials("restuser", "restbpm"); > client.getCredentialsProvider().setCredentials(new > AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), creds); > HttpPost post = new HttpPost(" > http://10.36.0.141:8080/bonita-server-rest/API/runtimeAPI/instantiateProcess/holamundo--1.0 > "); > > post.setHeader("content-type", "application/x-www-form-urlencoded"); > > List <NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); > nameValuePairs.add(new BasicNameValuePair("options", "user:admin")); > > post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); > > HttpResponse resp = client.execute(post); > > String respStr = EntityUtils.toString(resp.getEntity()); > > > TextView tv = new TextView(this); > tv.setText(respStr); > setContentView(tv); > > } catch(Exception ex){ > Log.e("ServicioRest","Error!", ex); > } > } > > Thanks!!! > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en