HTTP HTTP error POST request - EACCES socket failure (denial of rights)

I am trying to send a POST request to my local host from an Android application under Eclipse , but I get this error:

socket failed EACCES (Permission denied).

I do this through the apache.commons library. I used to try to connect via HttpClient, but there was a similar error:

Connect to myhost .

Here is the code:

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) { } } } }); 
+6
source share
2 answers

Do you have INTERNET permissions in the manifest?

Check out AndroidManifest.xml for subsequent lines

 <uses-permission android:name="android.permission.INTERNET" /> 
+23
source

Are you trying to connect to the local machine? I think instead of 127.0.0.1 it should be 10.0.2.2

See here: http://developer.android.com/guide/developing/devices/emulator.html#networkaddresses

+1
source

Source: https://habr.com/ru/post/909434/


All Articles