0
我聽說Post是最受歡迎的,同時也是達到具有密碼/敏感信息的鏈接。在基本身份驗證中如何獲取比發佈更好的apache http客戶端(Java編程)
問題1:我知道Post比名稱 - 值對參數更好,因爲Get將它暴露在URL中,而Post不會。但是如果我們談論的是身份驗證,那麼使用什麼方法,因爲我將憑證設置爲HttpClient而不是HttpGet或HttpPost.So憑據無論如何都沒有公開。名稱 - 值對的封裝受益於使用POST。
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(target.getHostName(), target.getPort()),
new UsernamePasswordCredentials("user", "passwd"));
CloseableHttpClient httpClient = HttpClients.custom()
.setDefaultCredentialsProvider(credsProvider)
.build();
Q2。再次,我可以設置憑據作爲標題爲httppost以及像這樣的httpget。
String encoding = new BASE64Encoder().encode("user:passwd".getBytes());
httpGet.setHeader("Authorization", "Basic " + encoding);
httpPost.setHeader("Authorization", "Basic " + encoding);
哪裏的post方法優先於get方法?