我以这种方式呼叫webservice ..
public static String POST(String url, ArrayList<ModelLatLog> list,Context con){
InputStream inputStream = null;
String result = "";
AppLog.logString(TAG+"URL : "+url);
AppLog.logString(TAG+"ListSize: "+list.size());
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
String json = "[";
for(int j=0;j<list.size();j++){
JSONObject jsonObject = new JSONObject();
jsonObject.accumulate("DId", ""+list.get(j).get_idDevice());
jsonObject.accumulate("Lat", ""+list.get(j).getLat());
jsonObject.accumulate("Long", ""+list.get(j).getLong());
jsonObject.accumulate("DIn", ""+list.get(j).getDt());
jsonObject.accumulate("TIn", ""+list.get(j).getTm());
jsonObject.accumulate("Dce", ""+list.get(j).getDce());
if(j==0 ){
json = json+""+jsonObject.toString();
AppLog.logString(TAG+"if j: "+j);
}
else{
json = json+","+jsonObject.toString();
AppLog.logString(TAG+"else j: "+j);
}
}
json = json+"]";
AppLog.logString(TAG+"JSON: "+json);
StringEntity se = new StringEntity(json);
httpPost.setEntity(se);
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
HttpResponse httpResponse = httpclient.execute(httpPost);
int resopnceStatus = httpResponse.getStatusLine().getStatusCode();
AppLog.logString(TAG+"set data resopnceStatus: "+resopnceStatus);
inputStream = httpResponse.getEntity().getContent();
if(inputStream != null)
result = convertInputStreamToString(inputStream);
else
result = "Did not work!";
} catch (Exception e) {
e.printStackTrace();
AppLog.logString("InputStream"+ e.getLocalizedMessage());
}
return result;
}
AppLog不是它的log.d
它给了我像
这样的错误11-19 18:15:39.088: I/Service(32261): Utility: set data resopnceStatus: 500
11-19 18:15:39.096: I/Service(32261): result: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Receiver</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="en">Server was unable to process request. ---> Data at the root level is invalid. Line 1, position 1.</soap:Text></soap:Reason><soap:Detail /></soap:Fault></soap:Body></soap:Envelope>
答案 0 :(得分:0)
看起来web服务正在向您返回错误,因此HTTP POST调用实际上有效。
你发送的格式是否正确?看起来像是期待XML请求而你发送JSON。
答案 1 :(得分:0)
为什么你这么负担...... 只需使用排球服务......它会照顾好每一件事......
在Volley中使用 StringRequest 。你的任务很容易...... 在此处下载volley示例
答案 2 :(得分:0)
如果你还没有弄清楚你的问题,我相信ksoap2对于处理android上的webservices更直观,这个链接有一个很好的例子。
is there clear Example of Android ksoap2 returning array of objects from .Net Web service?