这里使用volley来进行网络事务,使用gson库将sqlite的值转换为json我尝试连接wcf服务但是得到了意外的响应400我的url就像这个localhost / service.svc / { param}在这个我需要传递值这里我已经深入了解如何解决这个问题让我发布我的代码:
listobj=account_sf_db.toServer();
Gson gson=new Gson();
String param=gson.toJson(listobj);
RequestQueue queue = Volley.newRequestQueue(getApplicationContext());
/* final String god=listobj.toString();
JSONObject yogan=new JSONObject();
int i=0;
JSONArray jsonArray=new JSONArray();
try {
for (Model_Account modlobj:listobj){
JSONObject jobj=new JSONObject();
jobj.put("yog", modlobj.getState());
jsonArray.put(i,jobj);
}
yogan.put("yoges",jsonArray);
}
catch (JSONException e) {
e.printStackTrace();
}*/
final String gods="yoga:";
final String URL="http://xx.xx.x.xx/xxx/xx/xxx.svc/Account/xx/"+param;
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response)
{
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
String god = error.toString();
}
}){
@Override
public Map<String, String> getHeaders ()throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("Content-Type", "application/x-www-form-urlencoded");
return params;
}
};
queue.add(stringRequest);
stringRequest.setRetryPolicy(new DefaultRetryPolicy(5000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
}