gpt4 book ai didi

Android - Volley 库 : Session expired issue in SSL production environment

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:21:06 26 4
gpt4 key购买 nike

我有两个页面:第一个是登录页面,第二个是分类页面。输入凭据后在登录 API 中,我从响应 header 中获取作为 session ID 的响应。 session ID 将被保存,并将用于进一步的 API 调用。我正在尝试调用第二个 API(类别页面)。在此页面中,作为输入,我在请求 header 中传递保存的 session ID。收到“ session 已过期”的响应。还尝试在请求 header 中传递 Set-Cookie: PHPSESSID=d9f9sdkfjs9。但它没有用。

注意:

  1. 我只在生产环境中遇到过这个问题(包括 SSL)
  2. 我正在使用 volley 库来处理 API。


public void fnCallLoginAPI() {
try {
//DEMO URL
//final String URL="http://demo.io/api/api.php?m=login";
//LIVE URL
final String URL = "https://www.live.com/shop/api/api.php?m=login";
final String requestBody = "email=abc.b@xyz.com" + "&password=43443==" + "&strPlatform=i" + "&strDeviceToken=null";
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
String strResponse = response;
System.out.println("THE RESPONSE IS in PROFILE IS" + response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {

}
})
{
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<>();
headers.put("Cookie", "PHPSESSID=" + sessionID);
return headers;
}
@Override
public byte[] getBody() throws AuthFailureError {
byte[] body = new byte[0];
try {
System.out.println("THE REQIEST BODY IS" + requestBody);
body = requestBody.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
Log.e("TAG", "Unable to gets bytes from JSON", e.fillInStackTrace());
}
return body;
}
};

AppApplication.getInstance().addToRequestQueue(stringRequest, "assignment");
} catch (Exception e) {

}
}


public void fnCallCateGoryAPI(){
try { final String URL ="https://www.live.com/shop/api/api.php?m=getcategories";
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
String strResponse = response;
System.out.println("THE RESPONSE IS in PROFILE IS" + response);
JSONObject jsonObj = null;
try {
jsonObj = new JSONObject(strResponse);
sessionID = jsonObj.optString("session_id");
System.out.print("sessionID" + sessionID);
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
})
{
};

AppApplication.getInstance().addToRequestQueue(stringRequest, "assignment");
} catch (Exception e) {}
}}

最佳答案

@fazil 从后端增加 token 过期时间后尝试

关于Android - Volley 库 : Session expired issue in SSL production environment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50982975/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com