【发布时间】:2019-03-04 07:44:54
【问题描述】:
我在后端环境中使用 nodeJS,并且大多数 API 都准备好了。由于Java Spreadsheet component,我想在前端使用 Vaading。我查看了 Bakery 示例并设计了一个登录页面,该页面将用户凭据发送到我的后端 API。这是向服务器发送 POST 请求的代码。
public void submit(String username, String password) throws IOException {
JSONObject json = new JSONObject();
json.put("username", username);
json.put("password", password);
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
try {
HttpPost request = new HttpPost(URL);
HttpResponse response;
StringEntity params = new StringEntity(json.toString());
request.addHeader("content-type", "application/json");
request.setEntity(params);
response = httpClient.execute(request);
if(response.getStatusLine().getStatusCode() == 200) {
System.out.println("Okey!");
// The response contains token. How can I store this token?
// Also, How can I use the stored token for future Authentication:Bearer?
}
}
catch(Exception ex) {
System.out.println(ex);
}
finally {
httpClient.close();
}
}
我想将响应的令牌存储在某个地方(我可以将它存储在 React 中的 cookie 对象中。但是,我不熟悉这种语言)并从这个存储中获取令牌(可能是 cookie,如何在Java web中实现Cookie?)每次我发出请求时。
【问题讨论】:
-
仍然是一个有效的问题