我正在使用凌空发送一些帖子数据。这是我的代码。它是后台服务的一个片段。如果您还想要其他文件,请告诉我。我已经添加了互联网许可。
public void onLocationChanged(final Location location) {
mCurrentLocation = location;
pref.setLocation(location);
String url = getResources().getString(R.string.hostname); // it's a normal http
StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(getApplicationContext(), "Location sent", Toast.LENGTH_SHORT).show();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
String errorMessage = "Err - data:"+error.getMessage();
Toast.makeText(getApplicationContext(), errorMessage, Toast.LENGTH_SHORT).show();
}
})
{
@Override
protected Map<String,String> getParams(){
Map<String,String> params = new HashMap<String, String>();
params.put(KEY_USERID,pref.getUserId());
params.put(KEY_LAT,String.valueOf(location.getLatitude()));
params.put(KEY_LNG,String.valueOf(location.getLongitude()));
return params;
}
};
queue.add(stringRequest);
}
答案 0 :(得分:0)
实际上我看到其中一个参数UserId具有Null值,这就产生了问题