本文整理匯總了Java中org.apache.http.impl.client.HttpClients.createMinimal方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpClients.createMinimal方法的具體用法?Java HttpClients.createMinimal怎麽用?Java HttpClients.createMinimal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.impl.client.HttpClients
的用法示例。
在下文中一共展示了HttpClients.createMinimal方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: cipherPassword
import org.apache.http.impl.client.HttpClients; //導入方法依賴的package包/類
/**
* Cipher password of Bilibili account, use for username and password login which feature is not finished yet.
*
* @param password password of Bilibili account
* @return ciphered password
*/
public static String cipherPassword(String password) throws Exception {
String hash;
String key;
//獲取 hash 和 key
try (CloseableHttpClient closeableHttpClient = HttpClients.createMinimal()) {
JSONObject jsonObject = JSON.parseObject(
EntityUtils.toString(
closeableHttpClient.execute(
new HttpGet("http://passport.bilibili.com/login?act=getkey")
).getEntity()
)
);
hash = jsonObject.getString("hash");
key = jsonObject.getString("key");
}
//計算密碼密文
RSAPublicKey rsaPublicKey = new RSAPublicKeyImpl(
Base64.getDecoder().decode(
key.replace("-----BEGIN PUBLIC KEY-----", "")
.replace("-----END PUBLIC KEY-----", "")
.replace("\n", "")
.getBytes()
)
);
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, rsaPublicKey);
return new String(
Base64.getEncoder().encode(
cipher.doFinal((hash + password).getBytes())
)
);
}
示例2: createClient
import org.apache.http.impl.client.HttpClients; //導入方法依賴的package包/類
@Override
protected HttpClient createClient() {
return HttpClients.createMinimal();
}