【问题标题】:How Get is better than Post in Basic Authentication apache http client (Java Programming)在基本身份验证 apache http 客户端(Java 编程)中 Get 如何优于 Post
【发布时间】:2016-11-30 19:35:21
【问题描述】:

我听说在到达包含密码/敏感信息的链接时,最喜欢使用 Post。

Q1.我知道对于名称-值对参数,Post 比 Put 更好,Get 将它暴露在 URL 中,而 Post 没有。但是,如果我们谈论的是身份验证,那么当我将凭据设置为 HttpClient 而不是 HttpGet 或 HttpPost 时,我使用什么方法有什么关系。所以无论如何凭据都不会暴露。名称-值对的封装通过使用受益发布。

CredentialsProvider credsProvider = new BasicCredentialsProvider();

credsProvider.setCredentials(
    new AuthScope(target.getHostName(), target.getPort()),
    new UsernamePasswordCredentials("user", "passwd"));
CloseableHttpClient httpClient = HttpClients.custom()
    .setDefaultCredentialsProvider(credsProvider)
    .build();

第二季度。同样,我可以将凭据设置为 httppost 的标头,也可以像这样设置为 httpget ..

String encoding = new BASE64Encoder().encode("user:passwd".getBytes());
httpGet.setHeader("Authorization", "Basic " + encoding);
httpPost.setHeader("Authorization", "Basic " + encoding);

post 方法在哪里优先于 get 方法?

【问题讨论】:

    标签: java authentication post get httpclient


    【解决方案1】:

    我认为在使用密码时,无论谁说 post 比 get 更好,这意味着密码将成为 get 请求中 url 的一部分,这显然是不好的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-03
      • 1970-01-01
      • 2011-10-27
      • 2011-05-05
      • 1970-01-01
      • 1970-01-01
      • 2018-10-20
      • 2022-06-13
      相关资源
      最近更新 更多