本文整理汇总了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);
}