Volley 추가 쿠키 요약
2655 단어 Android 오픈 소스 프레임워크
우선StringRequest, JosonRequest, ImageRequest는 모두 Volley를 계승하는 핵심 클래스이다
getHeaders () 방법을 다시 쓰면 됩니다.
private Map sendHeader = new HashMap(1);
@Override
public Map getHeaders() throws AuthFailureError {
// ,
String cookies = "";
cookies = "visit-source=" + VERSION_SOURCE + ";" + "channel=" + Utils.getChannelValue
(MainApplication.getApplication()) + ";" + "current-version=" + versionName + ";"
+ PreferenceFile.getResponseCookies(MainApplication.getApplication()
.getApplicationContext());
if (!TextUtils.isEmpty(token)) {
+ token);
cookies = cookies + ";" + "adw_id=" + token;
}
sendHeader.put("cookie",cookies);
return sendHeader;
}
또한, 서버가 전송하는 쿠키가 필요할 때가 있는데 요청할 때 다시 보내면 어떡하죠, 우선 백스테이지에서 전송되는 쿠키가
Request에서 아주 중요한 방법이 하나 있는데parseNetworkResponse입니다. 방법을 바꾸면
@Override
protected Response parseNetworkResponse(NetworkResponse response) {
String jsonString = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
LogUtils.logD("Volley POST Response: ", "get data in parseNetworkResponse " + new String(response.data));
String responseCookiesStr = response.headers.get("Set-Cookie");
// , request
if (responseCookiesStr!= null && responseCookiesStr.contains("BUID")) {
PreferenceFile.saveResponseCookies(MainApplication.getApplication().getApplicationContext(), responseCookiesStr);
}
// jsonObject deliverResponse , onResponse
JSONObject jsonObject = new JSONObject(jsonString);
LogUtils.logD("Volley JsonObjectPOST: ", "jsonObject " + jsonObject.toString());
return Response.success(jsonObject, HttpHeaderParser.parseCacheHeaders(response));
}
그리고 최근에 이 부분을 처리할 때 Volley 프레임워크를 사용하지 않을 때 백스테이지와 상호작용을 하지 않았습니다. 나중에 너무 Nginx가 자동으로 쿠키를 추가했지만 Volley를 교체한 후에 Volley가 스위치를 꺼서 그런지 어떻게 해야 할지 모르겠습니다. 밑에 있는 코드를 봐도 찾을 수 없습니다.그래서 헤더 파일을 추가할 때 백엔드에 필요한 쿠키, 즉 위의 양쪽 코드를 추가해서 해결한다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Volley 추가 쿠키 요약최근에 Volley 프레임워크를 교체하는 작업을 했습니다. 먼저 Volley가 매우 강하고 네트워크 대기열에 대한 요청, 이미지 다운로드 캐시 메커니즘이 모두 최적화되었습니다.현재 매우 자주 사용되는 중요한 네트워크...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.