Android Can';t在本地服务器上使用KSoap2发布数据
我有一个.net Api在服务器上发送数据。我正在使用KSoap2发布数据,但失败了。我正在使用代码Android Can';t在本地服务器上使用KSoap2发布数据,android,api,ksoap2,Android,Api,Ksoap2,我有一个.net Api在服务器上发送数据。我正在使用KSoap2发布数据,但失败了。我正在使用代码 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new backMethod().execute(); // This is a
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new backMethod().execute(); // This is an important Step
}
public class backMethod extends AsyncTask<String, Object, Object > {
private final ProgressDialog dialog = new ProgressDialog(MainActivity.this);
@Override
protected void onPreExecute() {
this.dialog.setMessage("Checking...");
this.dialog.show();
}
@Override
protected void onPostExecute(Object result) {
//Here All your UI part is Done
if (result != null) {
TextView tv=(TextView)findViewById(R.id.textView1);
tv.setTag(result);
} else {
Toast.makeText(getApplicationContext(),
"Result Found is == " + result + "", Toast.LENGTH_LONG).show();
}
super.onPostExecute(result);
if (this.dialog.isShowing()) {
this.dialog.dismiss();
}
super.onPostExecute(result);
}
@Override
protected Object doInBackground(String... params) {
SoapObject request = new SoapObject(NAMESPACE, OPERATION_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
try {
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
response = (SoapObject) envelope.getResponse();
//here SoapPrimitive is an important part
} catch (Exception e) {
e.printStackTrace();
}
return response;
}
创建时受保护的void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new backMethod().execute();//这是一个重要的步骤
}
公共类backMethod扩展了AsyncTask{
私有最终ProgressDialog=新建ProgressDialog(MainActivity.this);
@凌驾
受保护的void onPreExecute(){
this.dialog.setMessage(“正在检查…”);
this.dialog.show();
}
@凌驾
受保护的void onPostExecute(对象结果){
//在这里,您的所有UI部分都完成了
如果(结果!=null){
TextView tv=(TextView)findViewById(R.id.textView1);
tv.setTag(结果);
}否则{
Toast.makeText(getApplicationContext(),
找到的结果为==“+Result+”,Toast.LENGTH_LONG).show();
}
super.onPostExecute(结果);
if(this.dialog.isShowing()){
this.dialog.disclose();
}
super.onPostExecute(结果);
}
@凌驾
受保护对象doInBackground(字符串…参数){
SoapObject请求=新的SoapObject(名称空间、操作名称);
SoapSerializationEnvelope=新的SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(请求);
试一试{
HttpTransportSE androidHttpTransport=新的HttpTransportSE(URL);
调用(SOAP_操作,信封);
response=(SoapObject)envelope.getResponse();
//这是一个重要的部分
}捕获(例外e){
e、 printStackTrace();
}
返回响应;
}
调试时代码流自动移动到catch块,并给出网络未找到的异常