我知道有很多类似意图的问题,但我没有找到任何可以解决这个错误的答案 问题:我想从我的Android应用程序访问.net webservice,我收到此错误。 UnknownHostException:主机未解析:webadress.com:80 早些时候我在模拟器上尝试这个,但现在甚至在设备上也得到了相同的错误.... 伙计们帮我解决问题
ma代码是:
public class FirstAppUI extends Activity {
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL =
//"http://192.168.41.201:52002/WebServiceAvail/Service.asmx";
"http://nautilussoft.biz.whbus12.onlyfordemo.com/staging/litigation/litwebservice.asmx";
private static final String SOAP_ACTION = "http://tempuri.org/";
private static final String METHOD_NAME = "GetUserByUserName(a,10)";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv= (TextView)findViewById(R.id.TextView01);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope =
new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
//Toast.makeText(getBaseContext(), "received object", Toast.LENGTH_SHORT).show();
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
//Toast.makeText(getBaseContext(), "received object", Toast.LENGTH_SHORT).show();
tv.setText("Received :" + resultsRequestSOAP.toString());
} catch (MalformedURLException e) {
e.printStackTrace();
Log.e("APP", "MalformedURLException while sending\n" + e.getMessage());
tv.setText("Malformedexception"+e);
}
catch(Exception e1)
{tv.setText("exception"+e1);}
}
}
答案 0 :(得分:0)
无法访问主机或信息所在的服务器,因此您收到此错误。这可能是由于各种原因,例如您没有连接到Internet,并且在尝试连接到服务器时连接丢失并且URL可能是错误的。
如果您在浏览器中收到来自您的网络服务的回复消息,则应用程序中存在问题,否则网络连接出现问题。
答案 1 :(得分:0)
使用“http://www.tempuri.org/”;取代“http://tempuri.org/”;
答案 2 :(得分:0)
“就像你没有连接到互联网一样,尝试连接服务器时连接丢失了,网址也可能出错。”
请检查模拟器中的互联网连接