【发布时间】:2016-02-07 00:54:36
【问题描述】:
也许是因为我不是android开发的——但我不明白我添加参数的两种方式之间的区别。
String[] 不是字符串吗?
例如,如果我在下面运行我的 void onclick。网络服务按预期工作
public void onClick(View v) {
new Thread() {
@Override
public void run() {//Create request
try {
//start SoapObject
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
/*List<String> ArgumentPipeValue = new ArrayList<String>();
ArgumentPipeValue.add("_caseId|apples");
for (String arg : ArgumentPipeValue) {
String[] splitArgs = arg.split("|");
request.addProperty(splitArgs[0],splitArgs[1]);;
}*/
request.addProperty("_caseId", "apples");
//create the envelope
SoapSerializationEnvelope envelope = getSoapSerializationEnvelope(request);
//Needed to make the internet call
HttpTransportSE androidHttpTransport = getHttpTransportSE();
//this is the actual part that will call the webservice
androidHttpTransport.call(SOAP_ACTION, envelope);
//SoapObject soapResponse = (SoapObject) envelope.getResponse();
SoapPrimitive results = (SoapPrimitive)envelope.getResponse();
} catch (Exception e) {
e.printStackTrace();
Log.w("myApp", e.getMessage());
Log.w("myApp", e.getCause());
}
}
}.start();
}
但是,如果我按以下方式运行 Web 服务,则会收到错误 Unexpected token (position:TEXT Bad Request@1:12 in java.io.InputStreamReader@3709d6f6)
public void onClick(View v) {
new Thread() {
@Override
public void run() {//Create request
try {
//start SoapObject
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
List<String> ArgumentPipeValue = new ArrayList<String>();
ArgumentPipeValue.add("_caseId|apples");
for (String arg : ArgumentPipeValue) {
String[] splitArgs = arg.split("|");
request.addProperty(splitArgs[0],splitArgs[1]);
}
//request.addProperty("_caseId", "apples");
//create the envelope
SoapSerializationEnvelope envelope = getSoapSerializationEnvelope(request);
//Needed to make the internet call
HttpTransportSE androidHttpTransport = getHttpTransportSE();
//this is the actual part that will call the webservice
androidHttpTransport.call(SOAP_ACTION, envelope);
//SoapObject soapResponse = (SoapObject) envelope.getResponse();
SoapPrimitive results = (SoapPrimitive)envelope.getResponse();
} catch (Exception e) {
e.printStackTrace();
Log.w("myApp", e.getMessage());
Log.w("myApp", e.getCause());
}
}
}.start();
}
唯一的区别是我通过request.addProperty("_caseId", "apples");而不是request.addProperty(splitArgs[0],splitArgs[1]);添加属性
我错过了什么?为什么会这样?
【问题讨论】:
-
数组不是字符串,不是