Hello!
I have a problem with my app, when I try to get data from a remote
server (in local network). I already try this:
1º: I made a Ad-Hoc network with the server (apache2 + php5 + mysql5),
and everything works!. I use this method
public static int userLoginPSG(String user, String pass, String IMEI,
String number){
//Arreglo que contiene los pares de datos: variable y valor
ArrayList<NameValuePair> nameValuePairs = new
ArrayList<NameValuePair>();
nameValuePairs.add(new
BasicNameValuePair(RQ_FUNCTION,RQ_F_LOGIN));
nameValuePairs.add(new BasicNameValuePair(RQ_USER,user));
nameValuePairs.add(new BasicNameValuePair(RQ_PASS,pass));
nameValuePairs.add(new BasicNameValuePair(RQ_IMEI,IMEI));
//Realiza la consulta HTTP POST
InputStream is = httpResponse(URL,nameValuePairs);
//Convierte la respuesta (InputStream) a un String
String response = null;
if (is != null)
response = convertInputStream2String(is);
else
//No se pudo conectar al servidor
return -1;
//Realiza la transformación de los datos a JSON
int isLogged = -1;
if ((response !=
null)&&(response.length()>0)&&(response.compareToIgnoreCase("null")!
=0))
isLogged = ParserJSON2VO.loginJSON2Boolean(response);
//Se retorna el valor
return isLogged;
}
public static InputStream httpResponse(String url,
ArrayList<NameValuePair> nameValuePairs){
//Realiza la consulta HTTP POST
InputStream is = null;
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
HttpGet httpGet = new HttpGet(url);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
is = null;
}
return is;
}
And the server returns me a JSON encode... no problems.
-----------------------------------------------------------------------------
2º: In a local network, with a special APN, I can connect my
cellphone. I use the browser to test the file .php and put som entries
like
http://172.29.XX.XX/bll.php?f=0&user=cmoreira&pass=kjsahdkhasdk
And I got results form that. (all correct)
3º: Now, the problem is when I try to connect (using code) in the
local network to the server... the app waits in "HttpResponse response
= httpclient.execute(httppost);" for ever and ever.. and... ever...
4º I used
public static InputStream getInputStreamFromUrl(String urls) {
HttpURLConnection con = null;
URL url;
InputStream is=null;
try {
url = new URL(urls);
con = (HttpURLConnection) url.openConnection();
con.setReadTimeout(10000 /* milliseconds */);
con.setConnectTimeout(15000 /* milliseconds */);
con.setRequestMethod("GET");
con.setDoInput(true);
//con.addRequestProperty("Referer",
"http://blog.dahanne.net");
// Start the query
con.connect();
is = con.getInputStream();
}catch (IOException e) {
//handle the exception !
e.printStackTrace();
}
return is;
And I got the same problem in con.connect();
"SocketTimeOutException", "Socket is not connected"
What could be the reason? some proxy in server? in network?...
THX!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en