我想在android studio中使用ksoap
lib。
但我还没有得到足够的承认。
(我总是使用Volley
lib从php api发送/接收,它工作正常。)
网址: http://sms141.ir/sms141_webservice.asmx
我的职能:
public object[] CheckUsers(string number , string user , string pass)
SOAP_ACTION
和NAMESPACE
变量是否正确?
private static final String SOAP_ACTION = "http://sms141.ir/CheckUsers";
private static final String METHOD_NAME = "CheckUsers";
private static final String NAMESPACE = "http://sms141.ir";
private static final String URL = "http://sms141.ir/sms141_webservice.asmx";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sms_login);
myAsyncTask myRequest = new myAsyncTask();
myRequest.execute();
}
private class myAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
// tv.setText(response);
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... arg0) {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("number", "value");
request.addProperty("user", "value");
request.addProperty("pass", "value");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(URL);
httpTransport.debug = true;
try {
httpTransport.call(SOAP_ACTION, envelope);
}catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} //send request
SoapObject result = null;
try {
result = (SoapObject)envelope.getResponse();
} catch (SoapFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.d("App",""+result.getProperty(1).toString());
String response = result.getProperty(1).toString();
Log.e("result","0"+response);
return null;
}
}
我收到这些错误:
> 06-17 18:32:02.751 11495-11515/com.almas.mehr.sms E/AndroidRuntime﹕
> FATAL EXCEPTION: AsyncTask #1
> java.lang.RuntimeException: An error occured while executing doInBackground()
> at android.os.AsyncTask$3.done(AsyncTask.java:299)
> at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
> at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
> at java.util.concurrent.FutureTask.run(FutureTask.java:239)
> at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
> at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
> at java.lang.Thread.run(Thread.java:856)
> Caused by: java.lang.NullPointerException
> at com.almas.mehr.sms.Login$myAsyncTask.doInBackground(Login.java:211)
> at com.almas.mehr.sms.Login$myAsyncTask.doInBackground(Login.java:166)
> at android.os.AsyncTask$2.call(AsyncTask.java:287)
> at java.util.concurrent.FutureTask.run(FutureTask.java:234)
> at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
> at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
> at java.lang.Thread.run(Thread.java:856)
答案 0 :(得分:1)
从我对你的问题的理解,你只需要知道如何使用KSOAP2库与android与服务器进行通信。
以下是您将获得实施的链接
http://karanbalkar.com/2014/03/tutorial-78-using-ksoap2-in-android/