java post 403_validation - 使用从GET请求接收的CSRF令牌在Java中进行POST-403-禁止-CSRF令牌验证错误 - 堆栈内存溢出...

CSRF令牌验证失败-403错误-禁止我不知道它失败的原因。

-提供正确的CSRF令牌值-还提供了cookie

static OkHttpClient client = new OkHttpClient();

public void run() throws IOException {

String[] headCookie = MyGETRequest();

POSTRequest(headCookie);

}

public static String[] MyGETRequest() throws IOException {

Request request = new Request.Builder()

.url("GET URL")

.get()

.addHeader("x-csrf-token", "FETCH")

.addHeader("authorization", "BASICAuthentication string")

.build();

Response response = client.newCall(request).execute();

String ar[] = new String[2];

ar[0] = response.headers().get("set-cookie");

ar[1] = response.headers().get("x-csrf-token");

response.close();

return ar;

}

public void POSTRequest(String[] headerCookie) throws IOException {

MediaType mediaType = MediaType.parse("application/json");

RequestBody body = RequestBody.create(mediaType,"POST BODY");

Request request = new Request.Builder()

.url("POST URL")

.post(body)

.addHeader("set-cookie", headerCookie[0])

.addHeader("x-csrf-token", headerCookie[1])

.addHeader("authorization", "BASICAuthentication string - same as GET")

.addHeader("accept", "application/json")

.addHeader("content-type", "application/json")

.build();

Response response = client.newCall(request).execute();

response.close();

}

POST应该成功。 我搜索了各种论坛,所有论坛都以类似的方式进行POST

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值