需要X-CSRF令牌

时间:2018-07-27 10:16:26

标签: java http post

URL url3 = new URL("https://52.36.28.121/sap/opu/odata/ACNLQD/ALPS_SRV/CourseActivitySet");
                URLConnection con = url3.openConnection();
                HttpURLConnection http = (HttpURLConnection)con;

                http.setRequestMethod("POST"); // PUT is another valid option
                http.setDoOutput(true); 
                http.setRequestProperty("Authorization", "Basic " + encoding);
                http.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
                http.setRequestProperty("Accept", "application/json");
                http.setRequestProperty("x-csrf-token", connection.getHeaderField("x-csrf-token"));

                System.out.println(http.getHeaderFields());

我已经从GET方法中检索了一个令牌,现在将其传递给POST方法。 但是当我检查header字段时,它为我提供了空白令牌。

这是我的GET

connection.setRequestMethod("GET");
            connection.setDoOutput(true);
            connection.setRequestProperty("Content-Type", "text/plain");
            connection.setRequestProperty("Authorization", "Basic " + encoding);
            connection.setRequestProperty("x-csrf-token", "fetch");

我对SetProperty做错了吗?

x-csrf-token=[Required]

0 个答案:

没有答案