gpt4 book ai didi

android - 调用 Web 服务时出错

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

即使在添加了 kSOAP 2 library jar 文件后,我也无法调用 web 服务

源代码:

  package com.example.web;  

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

public class MyWebCall extends Activity {
TextView tv;
String Name_Space="http://web.exampl.com/";
String Method_Name="add";
String Soap_Action="http://web.exampl.com/add";
String URL="http://MyServerIPaddress:8081/WebService/services/MyWebService?wsdl";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv=(TextView)findViewById(R.id.txt);
SoapObject request=new SoapObject(Name_Space,Method_Name);
PropertyInfo pi1=new PropertyInfo();
pi1.setName("op1");
pi1.setValue(6);
pi1.setType(int.class);
request.addProperty(pi1);
PropertyInfo pi2=new PropertyInfo();
pi2.setName("op1");
pi2.setValue(9);
pi2.setType(int.class);
request.addProperty(pi2);
SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
AndroidHttpTransport androidHttpTransport=new AndroidHttpTransport(URL);
try{
androidHttpTransport.call(Soap_Action,envelope);
SoapObject response=(SoapObject) envelope.getResponse();
int result=Integer.parseInt(response.getProperty(0).toString());
System.out.println("Result ::::::::::::::: "+result);
tv.setText(response.getProperty(0).toString());
Toast.makeText(getApplicationContext(), response.getProperty(0).toString(),Toast.LENGTH_SHORT).show();
}catch(Exception e){
e.printStackTrace();
}
}
}

我觉得 jar 里少了几个类。我从哪里可以下载合适的 jar 文件?请帮助我。

感谢和问候,
斯内哈

最佳答案

AndroidHttpTransport androidHttpTransport=new AndroidHttpTransport(URL); 

我已将这一行更改为:

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 

而且效果很好。
也感谢完整包 rekaszeru。

关于android - 调用 Web 服务时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5674851/

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