本文整理匯總了Java中org.apache.http.impl.auth.BasicScheme.authenticate方法的典型用法代碼示例。如果您正苦於以下問題:Java BasicScheme.authenticate方法的具體用法?Java BasicScheme.authenticate怎麽用?Java BasicScheme.authenticate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.impl.auth.BasicScheme
的用法示例。
在下文中一共展示了BasicScheme.authenticate方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: read
import org.apache.http.impl.auth.BasicScheme; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
protected final <T> T read(ContentHandler handler) throws IOException {
String spec = mUri.toString();
URL url = new URL(spec);
HttpURLConnection http = (HttpURLConnection) url.openConnection();
try {
String password = PasswordManager.get(mContext).getPassword(mUri.getAuthority());
if (password != null) {
Credentials credentials = new UsernamePasswordCredentials("", password);
Header authorization = BasicScheme.authenticate(credentials, HTTP.UTF_8, false);
http.setRequestProperty(authorization.getName(), authorization.getValue());
}
int responseCode = http.getResponseCode();
String responseMessage = http.getResponseMessage();
if (responseCode != HttpURLConnection.HTTP_OK) {
throw new HttpResponseException(responseCode, responseMessage);
}
return (T) handler.getContent(http);
} finally {
http.disconnect();
}
}
示例2: generateBasicAuthHeader
import org.apache.http.impl.auth.BasicScheme; //導入方法依賴的package包/類
protected Header generateBasicAuthHeader(HttpUriRequest request, Configuration configuration) {
Header basicAuthHeader;
BasicScheme basicScheme = new BasicScheme();
try {
basicAuthHeader = basicScheme.authenticate(
new UsernamePasswordCredentials(configuration.getUsername(), configuration.getPassword()),
request,
HttpClientContext.create());
} catch (Exception e) {
throw new BasicAuthException(e);
}
return basicAuthHeader;
}
示例3: generateBasicAuthHeader
import org.apache.http.impl.auth.BasicScheme; //導入方法依賴的package包/類
private Header generateBasicAuthHeader(HttpUriRequest request, Configuration configuration) {
Header basicAuthHeader;
BasicScheme basicScheme = new BasicScheme();
try {
basicAuthHeader = basicScheme.authenticate(
new UsernamePasswordCredentials(configuration.getUsername(), configuration.getPassword()),
request,
HttpClientContext.create());
} catch (Exception e) {
throw new BasicAuthException(e);
}
return basicAuthHeader;
}
示例4: generateBasicAuthHeader
import org.apache.http.impl.auth.BasicScheme; //導入方法依賴的package包/類
private Header generateBasicAuthHeader(HttpUriRequest request, Settings settings) {
Header basicAuthHeader;
BasicScheme basicScheme = new BasicScheme();
try {
basicAuthHeader = basicScheme.authenticate(
new UsernamePasswordCredentials(settings.getUsername(), settings.getPassword()),
request,
HttpClientContext.create());
} catch (AuthenticationException e) {
String msg = String.format("Error generating basic auth header for request: %s", request.toString());
statusMessageService.warn(msg, MODULE_NAME);
throw new DhisWebException(msg, e);
}
return basicAuthHeader;
}
示例5: addBasicAuthenticationHeader
import org.apache.http.impl.auth.BasicScheme; //導入方法依賴的package包/類
private HttpUriRequest addBasicAuthenticationHeader(HttpUriRequest request,
UsernamePasswordCredentials creds) {
Header hdr = BasicScheme.authenticate(creds, "utf-8", false);
request.addHeader(hdr);
return request;
}
示例6: signRequest
import org.apache.http.impl.auth.BasicScheme; //導入方法依賴的package包/類
private void signRequest(HttpUriRequest request) {
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, signUrl(privateKey, request.getURI().toString()));
Header basicAuthHeader = BasicScheme.authenticate(credentials, "US-ASCII", false);
request.addHeader(basicAuthHeader);
}