android与http的连接被拒绝

android与http的连接被拒绝,android,android-intent,android-activity,Android,Android Intent,Android Activity,我想将一些数据发送到另一台计算机上的本地主机服务器,但无法执行此操作。我正在使用mac,默认情况下我的防火墙是禁用的。我使用了另一台计算机的ip地址,我们在同一个网络中。我确实输入了所需的权限 这是logcat消息 09-22 08:06:46.343: D/OpenGLRenderer(1108): Enabling debug mode 0 09-22 08:07:37.943: W/EGL_genymotion(1108): eglSurfaceAttrib not implemented

我想将一些数据发送到另一台计算机上的本地主机服务器,但无法执行此操作。我正在使用mac,默认情况下我的防火墙是禁用的。我使用了另一台计算机的ip地址,我们在同一个网络中。我确实输入了所需的权限

这是logcat消息

09-22 08:06:46.343: D/OpenGLRenderer(1108): Enabling debug mode 0
09-22 08:07:37.943: W/EGL_genymotion(1108): eglSurfaceAttrib not implemented
09-22 08:07:41.443: W/EGL_genymotion(1108): eglSurfaceAttrib not implemented
09-22 08:08:01.379: D/InputStream(1108): Connection to http://172.22.111.225:8080 refused
这是我的密码

public class MainActivity extends Activity implements OnClickListener {

TextView tvIsConnected;
 EditText etName;
 EditText etCountry;
 EditText etTwitter;
 Button btnPost;

Person person;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // get reference to the views
    tvIsConnected = (TextView) findViewById(R.id.tvIsConnected);
    etName = (EditText) findViewById(R.id.etName);
    etCountry = (EditText) findViewById(R.id.etCountry);
    etTwitter = (EditText) findViewById(R.id.etTwitter);
    btnPost = (Button) findViewById(R.id.btnPost);

    // check if you are connected or not
    if(isConnected()){
        tvIsConnected.setBackgroundColor(0xFF00CC00);
        tvIsConnected.setText("You are conncted");
    }
    else{
        tvIsConnected.setText("You are NOT conncted");
    }

    // add click listener to Button "POST"
    btnPost.setOnClickListener(this);

}

public static String POST(String url, Person person){
    InputStream inputStream = null;
    String result = "";

    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

    nameValuePairs.add(new BasicNameValuePair("phonenumber",person.getName()));
    nameValuePairs.add(new BasicNameValuePair("peoplenumber",person.getCountry()));
    nameValuePairs.add(new BasicNameValuePair("remark",person.getTwitter()));

    try {

        // 1. create HttpClient
        HttpClient httpclient = new DefaultHttpClient();

        // 2. make POST request to the given URL
        HttpPost httpPost = new HttpPost(url);
        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));



        // 8. Execute POST request to the given URL
        HttpResponse httpResponse = httpclient.execute(httpPost);

        // 9. receive response as inputStream
        inputStream = httpResponse.getEntity().getContent();

        // 10. convert inputstream to string
        if(inputStream != null)
            result = convertInputStreamToString(inputStream);
        else
            result = "Did not work!";

    } catch (Exception e) {
        Log.d("InputStream", e.getLocalizedMessage());
    }

    // 11. return result
    return result;
}

public boolean isConnected(){
    ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Activity.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.isConnected()) 
            return true;
        else
            return false;    
}
@Override
public void onClick(View view) {

    switch(view.getId()){
        case R.id.btnPost:
            if(!validate())
                Toast.makeText(getBaseContext(), "Enter some data!", Toast.LENGTH_LONG).show();
            // call AsynTask to perform network operation on separate thread
            new HttpAsyncTask().execute("http://172.22.111.225:8080/OrderServer/orderServer");
        break;
    }

}
private class HttpAsyncTask extends AsyncTask<String, Void, String> {
    @Override
    protected String doInBackground(String... urls) {

        person = new Person();
        person.setName(etName.getText().toString());
        person.setCountry(etCountry.getText().toString());
        person.setTwitter(etTwitter.getText().toString());

        return POST(urls[0],person);
    }
    // onPostExecute displays the results of the AsyncTask.
    @Override
    protected void onPostExecute(String result) {
        Toast.makeText(getBaseContext(), "Data Sent!", Toast.LENGTH_LONG).show();
   }
}

private boolean validate(){
    if(etName.getText().toString().trim().equals(""))
        return false;
    else if(etCountry.getText().toString().trim().equals(""))
        return false;
    else if(etTwitter.getText().toString().trim().equals(""))
        return false;
    else
        return true;    
}
private static String convertInputStreamToString(InputStream inputStream) throws IOException{
    BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(inputStream));
    String line = "";
    String result = "";
    while((line = bufferedReader.readLine()) != null)
        result += line;

    inputStream.close();
    return result;

}   
}


在清单文件中授予该权限。

该权限如何

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

我确实给了许可,你可以清理项目,然后再试一次。这可能只有两种可能,一种是没有internet权限,另一种是url连接可能会被拒绝,因为它无法访问。请从测试应用程序的另一个浏览器中尝试该url。是否可以从其他来源连接到计算机?因为目标似乎不接受连接。这并不能提供问题的答案。若要评论或要求作者澄清,请在他们的帖子下方留下评论-你可以随时在自己的帖子上发表评论,一旦你有足够的评论,你就可以发表评论了。是的,对不起……我只是想发表评论,但我不能,因为声誉问题
<uses-permission android:name="android.permission.INTERNET" />