-3

使用 JWT 令牌发布请求 HttpClient(发现错误请求错误 /chunked:false)

CloseableHttpClient client = HttpClients.createDefault();
        HttpPost httpPost = new HttpPost(RestUrl.SAVE_INVENTORY);
        Gson gson = new Gson();
        String json = gson.toJson(inventoryDto);
        StringEntity entity = new StringEntity(json);
        httpPost.setEntity(entity);
        httpPost.setHeader("Accept", "application/json");
        httpPost.setHeader("Content-type", "application/json");
        httpPost.addHeader("Authorization", "JWT " +LoginDaoIMPL.token);
        CloseableHttpResponse response = client.execute(httpPost);
        client.close();
4

2 回答 2

1

API 期待“Bearer”而不是“JWT”,所以问题出在这段代码上

于 2020-04-29T11:16:54.073 回答
0

可能是这行代码给您带来了麻烦:

 httpPost.addHeader("Authorization", "JWT " +LoginDaoIMPL.token);

请注意,单词后面有一个空格JWT。删除空间。

于 2019-01-06T09:19:06.320 回答