android - 面对 Java.net.SocketException : Permission Denied

标签 android

我在 LogCat 中没有收到任何错误。代码中显示的ip是localhost ip地址。我的 AVD 中可以使用互联网。

我的 MainActivity.java 是:

公共(public)类 MainActivity 扩展 Activity {

private static final String SOAP_ACTION = "http://tempuri.org/add";
private static final String METHOD_NAME = "add";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://101.63.111.137/yash/DemoService.asmx";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    Button callMe = (Button) findViewById(R.id.b1);
    callMe.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            String responseData = getData();
            ((TextView) findViewById(R.id.textView1)).setText("Response Received is: " + responseData);
        }

    });

}

private String getData() {

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

    PropertyInfo pi = new PropertyInfo();
    pi.setName("i");
    pi.setValue(((EditText) findViewById(R.id.e1)).getText().toString());
    pi.setType(int.class);
    request.addProperty(pi);

    PropertyInfo pi2 = new PropertyInfo();
    pi2.setName("j");
    pi2.setValue(((EditText) findViewById(R.id.e2)).getText().toString());
    pi2.setType(int.class);
    request.addProperty(pi2);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);

    HttpTransportSE androidHttpTransport=new HttpTransportSE(URL);
    try {
        androidHttpTransport.call(SOAP_ACTION, envelope);
        SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
        return response.toString();
    } catch (Exception e) {
        e.printStackTrace();
        return e.toString();
    }
}

我在 AndroidManifest.xml 中添加了这些行

提前致谢。

最佳答案

您是否已将 INTERNET_ACCESS 权限添加到您的 list ?

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

SocketException

关于android - 面对 Java.net.SocketException : Permission Denied,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14797225/

相关文章:

Android:如何为特定主机使用 Wifi 网络,但让手机使用移动网络进行其他所有操作

android - 我正在为 android 上传照片

java - 我不断收到错误。不兼容的类型 : ArrayList<StudentDetails> cannot be converted to ArrayList<AndroidTargets>

android - Gradle:文件名、目录名或卷标语法不正确

java - 在android中使用AIDE时出现意外的声明结束消息,为什么?

java - 用于为我的应用程序选择启动语言的菜单(Android SDK)

java - TypeFace.createFromAsset 找不到字体错误

android - java.lang.NoClassDefFoundError : com. itextpdf.text.Document 错误

android - 同时使用 AIDL 和 Messenger

java - 移动项目文件夹后应用程序崩溃 android studio