gpt4 book ai didi

java - ECONNREFUSED(连接被拒绝)android连接到webservice

转载 作者:搜寻专家 更新时间:2023-11-01 07:57:51 25 4
gpt4 key购买 nike

尝试使用 soapui 连接到网络服务时出现连接被拒绝错误。当我尝试在 URL 中使用 127.0.0.1 时,错误是 ECONNREFUSED 但当我尝试 10.0.2.2 时,错误是连接超时。请有人帮忙。谢谢。这是我在 Main Activity 上的代码。

private static final String SOAP_ACTION = "http://tempuri.org/GetSMSOutgoing";
private static final String INSERT_INCOMING_SMS = "SaveSMSIncoming";
private static final String GET_OUTGOING_SMS = "GetSMSOutgoing";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://127.0.0.1:62499/WSsmsandroid.asmx?wsdl";

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

Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
getOutgoingSMS();
} catch (Exception e) {
Log.d("NOT CONNECTED: IOException", "NOT CONNECTED");
e.printStackTrace();
}

}
});

thread.start();

}

public String getOutgoingSMS() {
String outgoingSMS = null;

SoapObject request = new SoapObject(NAMESPACE, GET_OUTGOING_SMS);
request.addProperty("sentBy", "+639209100000");

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

HttpTransportSE ht = new HttpTransportSE(URL);
try {
ht.call(SOAP_ACTION, envelope);

SoapObject response2 = (SoapObject) envelope.getResponse();
denemeList = new String[response2.getPropertyCount()];

for (int i = 0; i < response2.getPropertyCount(); i++) {
denemeList[i] = response2.getProperty(i).toString();
}
outgoingSMS = response2.toString();

} catch (Exception e) {
e.printStackTrace();
}
return outgoingSMS;
}

最佳答案

要从 Android 模拟器访问您的 PC 本地主机,请使用 10.0.2.2 而不是 127.0.0.1。 localhost 或 127.0.0.1 指的是模拟设备本身,而不是运行模拟器的主机。

对于 Genymotion 使用:10.0.3.2 而不是 10.0.2.2

引用:http://developer.android.com/tools/devices/emulator.html#networkaddresses

PS.: connect failed: ECONNREFUSED 已经回答了

关于java - ECONNREFUSED(连接被拒绝)android连接到webservice,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25354723/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com