gpt4 book ai didi

java - Android Soap 服务调用的奇怪响应

转载 作者:行者123 更新时间:2023-12-02 08:13:48 26 4
gpt4 key购买 nike

我们有一个 Android 应用程序,我们正在尝试将其用于网络服务通信。

我们可以成功发送请求并获得包含以下代码 fragment 的响应。

public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

TextView textView = new TextView(this);

setContentView(textView);
//textView.setText();

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

request.addProperty("foo", "bar");
request.addProperty("foo", "bar");
request.addProperty("foo", "bar");
request.addProperty("foo", "bar");
request.addProperty("foo", "bar");
request.addProperty("foo", "bar");


Log.w(TAG, request.toString());
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;

envelope.setOutputSoapObject(request);
envelope.encodingStyle = "utf-8";
envelope.implicitTypes = false;
AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);

try

{
httpTransport.call(SOAP_ACTION, envelope);

KvmSerializable ks = (KvmSerializable)envelope.bodyIn;
for(int i=0;i < ks.getPropertyCount();i++)
{
ks.getProperty(i);
SoapObject soap = (SoapObject)ks.getProperty(i);
String tmp = soap.getProperty(0).toString();
textView.setText(tmp);
Log.w(TAG2, envelope.toString());
Log.w(TAG3, ks.getProperty(i).toString());

}

}
catch (Exception exception)
{
textView.setText(exception.toString());
Log.w(TAG4, exception);
}


}

现在,在 textView.setText(tmp); 中显示的请求响应显示如下响应:

anyType{foo=bar;foo=bar;foo=bar;}

而我们希望它返回为 foo = bar, foo = bar

任何点击和指点都将受到高度赞赏。提前致谢。

最佳答案

哪里有这些:

    SoapObject soap = (SoapObject)ks.getProperty(i);
String tmp = soap.getProperty(0).toString();

您需要使用这些:

    SoapObject soap = (SoapObject)ks.getProperty(i);
SoapObject tmp = soap.getProperty(0);
String foo = tmp.getProperty(0).toString();

我发现您使用复杂类型,您应该使用 HttpTransportSE 而不是 AndroidHttpTransport 已弃用。

希望对你有帮助

关于java - Android Soap 服务调用的奇怪响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6843803/

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