大佬教程收集整理的这篇文章主要介绍了响应 403 无效的 CSRF 令牌,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
嗨,我收到无效的 CSRF 令牌后,在第二次调用时收到了无效的 CSRF 令牌,然后使用该令牌更新了新请求。我怀疑是会话 ID 问题,但无法确定如何确保会话在第二次调用时仍然有效。任何建议都会很棒。
OkhttpClIEnt clIEnt = new OkhttpClIEnt.builder()
.cookieJar(new cookieJar() {
private final HashMap<String,List<cookie>> cookieStore = new HashMap<>();
@OverrIDe
public voID saveFromresponse(@NonNull httpUrl url,@NonNull List<cookie> cookies) {
cookieStore.put(url.host(),cookies);
}
@OverrIDe
public List<cookie> loadForrequest(@NonNull httpUrl url) {
List<cookie> cookies = cookieStore.get(url.host());
return cookies != null ? cookies : new ArrayList<cookie>();
}
})
.addInterceptor(new BasicAuthInterceptor("XXXXXX","YYYYYY"))
.readTimeout(10,TimeUnit.SECONDS)
.writeTimeout(10,TimeUnit.SECONDS)
.build();
request requestGet = new request.builder()
.url(ServerUrl)
.addheader("x-csrf-token","fetch")
.build();
responseGet = clIEnt.newCall(requestGet).execute();
Log.w("GetToken",String.valueOf(responseGet.code()));
if (responseGet.code() == 200) {
requestbody body = requestbody.create(MediaType.parse("application/xml"),payload);
request requestPost = new request.builder()
.url(CreateUrl)
.header("x-csrf-token",responseGet.headers("x-csrf-token").toString().replace("[","").replace("]",""))
.header("Content-Type",responseGet.headers("application/xml;charset=utf-8").toString().replace("[",""))
.post(body)
.build();
Log.w("GetToken",""));
responsePost = clIEnt.newCall(requestPost).execute();
public class BasicAuthInterceptor implements Interceptor {
private String credentials;
public BasicAuthInterceptor(String user,String password) {
this.credentials = Credentials.basic(user,password);
}
@OverrIDe
public ResponsE intercept(Chain chain) throws IOException {
request request = chain.request();
request authenticatedrequest = request.newBuilder()
.header("Authorization",credentials).build();
return chain.proceed(authenticatedrequest);
}
}
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的响应 403 无效的 CSRF 令牌全部内容,希望文章能够帮你解决响应 403 无效的 CSRF 令牌所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。