我正在尝试访问我的GetUserData.php文件,将存储在数据库中的用户信息显示在我的Android应用中的个人资料页面上。我有:
SharedPreferences sharedPreferences = getSharedPreferences(Config.sharedPref, Context.MODE_PRIVATE);
String sessionId = sharedPreferences.getString(Config.SID, "SessionID");
StringRequest stringRequest = new StringRequest(Request.Method.GET, Config.SERVER_ADDRESS + "GetUserData.php/?PHPSESSID=" + sessionId,
并且我的会话ID从用户首次登录时开始存储。但是我收到错误
BasicNetwork.performRequest:http://............/GetUserData.php/?PHPSESSID=54609c62fec7fc28631d708da687ab55
的意外响应代码500以下是该方法的其余部分:
private void getUserData() {
SharedPreferences sharedPreferences = getSharedPreferences(Config.sharedPref, Context.MODE_PRIVATE);
String sessionId = sharedPreferences.getString(Config.SID, "SessionID");
StringRequest stringRequest = new StringRequest(Request.Method.GET, Config.SERVER_ADDRESS + "GetUserData.php/?PHPSESSID=" + sessionId,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
JSONObject jsonObject = null;
try {
//json string to jsonobject
jsonObject = new JSONObject(response);
//get json sstring created in php and store to JSON Array
result = jsonObject.getJSONArray(Config.json_array);
//get username from json array
getUserInfo(result);
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
private void getUserInfo(JSONArray jsonArray){
for(int i = 0; i < jsonArray.length(); i++) {
try {
JSONObject json = jsonArray.getJSONObject(i);
userInfo.add(json.getString(Config.getUsername));
} catch (JSONException e) {
}
}
getFname.setText(userInfo.indexOf(2));
}
答案 0 :(得分:0)
要启用通过GET而不是cookie传递会话ID,您可能必须激活session.use_trans_sid
php.ini选项,默认情况下禁用该选项(这意味着,通过defaut,会话ID仅被传递通过cookies - 永远不会通过GET。)
答案 1 :(得分:0)
快速浏览一下......和GetUserData.php /?PHPSESSID = 54609c6 ...看起来很奇怪为什么/只是在.php之后?