Estoy intentando enviar una solicitud POST a mi localhost desde una aplicación de Android bajo Eclipse, pero estoy recibiendo este error:HTTP Android de error petición POST - socket no EACCES (permiso denegado)
socket failed EACCES (Permission denied).
I Estoy haciendo esto a través de la biblioteca apache.commons. He tratado de conectar a través de HttpClient antes, pero había un error similar:
Connect to myhost refused.
Aquí está el código:
public void onClick(View v) {
login = (EditText) findViewById(R.id.entry_login);
userLogin = login.getText().toString();
pwd = (EditText) findViewById(R.id.entry_password);
userPwd = pwd.getText().toString();
BufferedReader br = null;
HttpClient httpclient = new HttpClient();
PostMethod method = new PostMethod("http://127.0.0.1/testPost.php");
method.addParameter("name", "Arthur");
System.out.println("Login: " + userLogin);
try {
httpclient.executeMethod(method);
int returnCode = httpclient.executeMethod(method);
if (returnCode == HttpStatus.SC_NOT_IMPLEMENTED) {
System.err.println("The Post method is not implemented by this URI");
// Still consume the response body
method.getResponseBodyAsString();
}
else {
br = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));
String readLine;
while (((readLine = br.readLine()) != null)) {
System.err.println(readLine);
}
}
/* List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("name", "Arthur"));
nameValuePairs.add(new BasicNameValuePair("OP_ID", "10001"));
nameValuePairs.add(new BasicNameValuePair("IP_ADDRESS", "127.0.0.1"));
nameValuePairs.add(new BasicNameValuePair("FIELDS=field100", userLogin + "&field101=" + userPwd));
nameValuePairs.add(new BasicNameValuePair("REQ_TYPE=", "26"));
*/
System.out.println("http connection done well!");
// response.getStatusLine();
}
catch (Exception e) {
System.out.println(e.getMessage());
}
finally {
method.releaseConnection();
if (br != null)
try {
br.close();
}
catch (Exception fe) {
}
}
}
});
Buen consejo amigo, el mensaje de error anterior se ha ido, pero NullPointerException actual =), 1 punto a U. –
Hay un error EXCEPCIÓN FATAL: main; android.os.NetworkOnMainThreadException; android.BlockGuardPolicy.onNetwork, etc. Creo que el emulador sigue bloqueando la solicitud a través de sockets ... –
En NetworkOnMainThreadException vea mi respuesta aquí - http://stackoverflow.com/questions/9380166/fatal-exception-in-android/9380512#9380512 – Olegas