我生成了连接到服务器的应用程序,但它有以下错误,无法向服务器注册数据。我的代码如下。谷歌搜索后,我知道这是一个服务器错误,但我不知道哪里是错误。 Plz看看它并帮助我。 TNX
错误是:
q = (PackageContent.objects
.filter(package__pallet__isnull=False)
.values('product__name', 'package__art_number')
.annotate(models.Sum('count'))
)
ApplicationController类:
Volley: [223] BasicNetwork.performRequest: Unexpected response code 500 for https://xxxxx.com/set.php
发送数据的主要方法:
public class ApplicationController extends Application {
/**
* Log or request TAG
*/
public static final String TAG = "VolleyPatterns";
/**
* Global request queue for Volley
*/
private RequestQueue mRequestQueue;
/**
* A singleton instance of the application class for easy access in other places
*/
private static ApplicationController sInstance;
@Override
public void onCreate() {
super.onCreate();
// initialize the singleton
sInstance = this;
}
/**
* @return ApplicationController singleton instance
*/
public static synchronized ApplicationController getInstance() {
return sInstance;
}
/**
* @return The Volley Request queue, the queue will be created if it is null
*/
public RequestQueue getRequestQueue() {
// lazy initialize the request queue, the queue instance will be
// created when it is accessed for the first time
if (mRequestQueue == null) {
mRequestQueue = Volley.newRequestQueue(getApplicationContext());
}
return mRequestQueue;
}
/**
* Adds the specified request to the global queue, if tag is specified
* then it is used else Default TAG is used.
*
* @param req
* @param tag
*/
public <T> void addToRequestQueue(Request<T> req, String tag) {
// set the default tag if tag is empty
req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
VolleyLog.d("Adding request to queue: %s", req.getUrl());
getRequestQueue().add(req);
}
/**
* Adds the specified request to the global queue using the Default TAG.
*
* @param req
* @param tag
*/
public <T> void addToRequestQueue(Request<T> req) {
// set the default tag if tag is empty
req.setTag(TAG);
getRequestQueue().add(req);
}
/**
* Cancels all pending requests by the specified TAG, it is important
* to specify a TAG so that the pending/ongoing requests can be cancelled.
*
* @param tag
*/
public void cancelPendingRequests(Object tag) {
if (mRequestQueue != null) {
mRequestQueue.cancelAll(tag);
}
}
}
服务器端:
public void Send(View v) {
try {
final String URL = "xxxxxx";
// Post params to be sent to the server
HashMap<String, String> params = new HashMap<String, String>();
params.put("id", "8");
params.put("name", "divid");
params.put("email", "aa@my.com");
params.put("date", "2010-08-08 21:31:01");
params.put("Content-Type", "application/json; charset=utf-8");
JsonObjectRequest req = new JsonObjectRequest(URL, new JSONObject(params),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
VolleyLog.v("Response:%n %s", response.toString(4));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
NetworkResponse networkResponse = error.networkResponse;
if (networkResponse != null) {
Log.i("err0rMsg", "Volley -> Error. HTTP Status Code:"+networkResponse.statusCode);
}
if (error instanceof TimeoutError) {
Log.i("err0rMsg", "Volley -> TimeoutError");
}else if(error instanceof NoConnectionError){
Log.i("err0rMsg", "Volley -> NoConnectionError");
} else if (error instanceof AuthFailureError) {
Log.i("err0rMsg", "Volley -> AuthFailureError");
} else if (error instanceof ServerError) {
Log.i("err0rMsg", "Volley -> ServerError");
} else if (error instanceof NetworkError) {
Log.i("err0rMsg", "Volley -> NetworkError");
} else if (error instanceof ParseError) {
Log.i("err0rMsg", "Volley -> ParseError");
}
}
});