我正在尝试使用ksoap2-android来使用W3School测试网络服务。这是我的AsyncTask的代码:
private class MyAsyncTask extends AsyncTask<Integer, Void, SoapPrimitive> {
@Override
protected void onPreExecute() {
pgdProgress.show();
}
@Override
protected SoapPrimitive doInBackground(Integer... params) {
String SOAP_ACTION = "http://www.w3schools.com/xml/FahrenheitToCelsius";
String METHOD_NAME = "FahrenheitToCelsius";
String NAMESPACE = "http://www.w3schools.com/xml/";
String URL = "http://www.w3schools.com/xml/tempconvert.asmx";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("Fahrenheit", params[0]);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
try {
HttpTransportSE transport = new HttpTransportSE(URL);
transport.call(SOAP_ACTION, envelope);
return (SoapPrimitive) envelope.getResponse();
} catch (Exception e) {
Log.e("TEST", "KSOAP2", e);
}
return null;
}
@Override
protected void onPostExecute(SoapPrimitive soapPrimitive) {
pgdProgress.dismiss();
if(soapPrimitive != null)
txvOutput.setText(soapPrimitive.toString());
}
}
它适用于AVD模拟器(API 23),但不适用于我的平板电脑(API 19)。平板电脑的互联网连接有效,因为我可以浏览谷歌浏览器。我的App Project的最低SDK版本是API 15。
记录异常只是抛出这个:
01-27 10:28:14.604 10437-10601/com.android.wsconsumer E/TEST: KSOAP2
有什么想法吗?抱歉英语不好,希望你能理解。