我的代码如下:
public void testWebServiceForJson() {
TextView textView = new TextView(this);
setContentView(textView);
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
OPERATION_NAME);
ArrayList<String> list = new ArrayList<String>();
list.add("blah");
list.add("bleh");
JSONArray jsArray = new JSONArray(list);
String mStringArray[] = { "String1", "String2" };
JSONArray mJSONArray = new JSONArray(Arrays.asList(mStringArray));
request.addProperty("jsonArray", mJSONArray);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
try
{
httpTransport.call(SOAP_ACTION, envelope);
Object response = envelope.getResponse();
// SoapObject result = (SoapObject) envelope.bodyIn;
textView.setText("fafaf");
}
catch (Exception exception)
{
exception.printStackTrace();
textView.setText(exception.toString());
}
}
抛出异常:
您不必使用 ksoap2 将 json 发送到服务器。 Ksoap 用于与 SOAP Web 服务进行通信。
将 json 发送到服务器:
Reader r;
String url = "http://10.111.111.43:9000/XentivoCrm/services/VisitJSON";
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpost = new HttpPost(url);
InputStream data = null;
try {
ObjectMapper mapper = new ObjectMapper();
mapper.getSerializationConfig().setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
String json = mapper.writeValueAsString(mStringArray);
//I used jackson to create json, but built-in json.org will work
StringEntity se = new StringEntity(json);
httpost.setEntity(se);
httpost.setHeader("json", "application/json");
httpost.setHeader(HTTP.CONTENT_TYPE, "application/json");
HttpResponse response = httpClient.execute(httpost);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)