如何将获取 x-csrf-token 的能力添加到此脚本中?

问题描述

此外,当我运行脚本时,它会收到回复“HTTP/1.1 200 OK”,但我使用的地址应该需要 x-csrf-token,所以很奇怪。 我试图做的是最终使用 x crsf 令牌发出正确的 get 请求并获得回复,然后我将其转换为字符串和可读输出

    package com.company;

import org.apache.http.httpentity;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

public class ClientAuthentication {

    public static void main(String[] args) throws Exception {
        DefaultHttpClient httpclient = new DefaultHttpClient();
        try {
            httpclient.getCredentialsProvider().setCredentials(
                    new AuthScope("url",443),new UsernamePasswordCredentials("username","pass"));


                    HttpGet httpget = new HttpGet("url");

            System.out.println("executing request" + httpget.getRequestLine());
            HttpResponse response = httpclient.execute(httpget);
            httpentity entity = response.getEntity();

            System.out.println("----------------------------------------");
            System.out.println(response.getStatusLine());
            if (entity != null) {
                System.out.println("Response: " + entity.getContentType());
            }
            EntityUtils.consume(entity);
        } finally {
            httpclient.getConnectionManager().shutdown();
        }
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)