gpt4 book ai didi

java - 提出 SOAP 请求时出现问题

转载 作者:行者123 更新时间:2023-12-01 09:15:27 26 4
gpt4 key购买 nike

我正在尝试使用 ksoap2 库版本 3.6.2 向 SOAP API 发出请求。

问题是我收到错误消息:

"SoapFault - faultcode: 'soap:Server' faultstring: 'Server was unable to process request. ---> Object reference not set to an instance of an object.' faultactor: 'null' detail: org.kxml2.kdom.Node@338a49b".

我的代码如下所示:

String NAMESPACE = "x";
String METHOD_NAME = "x";
String SOAP_ACTION = "x";
String URL = "x";

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

request.addProperty("userName", "x");
request.addProperty("Password", "x");

//request.addProperty("token","token","?");

Log.i("SOAP: ", request.toString());

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.implicitTypes = false;
envelope.setOutputSoapObject(request);


HttpsTransportSE aht = new HttpsTransportSE("x", 8900, "x", 50000);
aht.debug = true;

// make call
try {

aht.call(SOAP_ACTION, envelope);
SoapObject result = (SoapObject) envelope.getResponse();

Log.i("RESP:", aht.responseDump.toString());
Log.i("RESPONSE: ", result.toString());

} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}

我认为问题可能在于它还需要一个属性,即我在代码中注释掉的属性。

如何添加带有属性的属性?像这样:<token Token=""> ,因为我认为这就是我缺少得到回复的原因。

我用 postman 测试了它,它工作得很好,但只有当我有这 3 个属性(用户名、密码和 token )时。

最佳答案

您可以使用addAttribute方法向属性添加属性。

试试这个代码,

request.addProperty("userName", "x");
request.addProperty("Password", "x");

SoapObject token = new SoapObject(NAMESPACE, "token");
token.addAttribute("Token", "your_token");
request.addSoapObject(token);

关于java - 提出 SOAP 请求时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40575180/

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