提出 soap 请求时出现问题
Problems making a soap request
我正在尝试使用 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 个属性(用户名、密码和令牌)时才有效。
您可以使用addAttribute
方法为属性添加属性。
试试这个代码,
request.addProperty("userName", "x");
request.addProperty("Password", "x");
SoapObject token = new SoapObject(NAMESPACE, "token");
token.addAttribute("Token", "your_token");
request.addSoapObject(token);
我正在尝试使用 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 个属性(用户名、密码和令牌)时才有效。
您可以使用addAttribute
方法为属性添加属性。
试试这个代码,
request.addProperty("userName", "x");
request.addProperty("Password", "x");
SoapObject token = new SoapObject(NAMESPACE, "token");
token.addAttribute("Token", "your_token");
request.addSoapObject(token);