本文整理了Java中com.github.kevinsawicki.http.HttpRequest.basic()
方法的一些代码示例,展示了HttpRequest.basic()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.basic()
方法的具体详情如下:
包路径:com.github.kevinsawicki.http.HttpRequest
类名称:HttpRequest
方法名:basic
[英]Set the 'Authorization' header to given values in Basic authentication format
[中]
代码示例来源:origin: org.codehaus.sonar/sonar-batch
@VisibleForTesting
void uploadMultiPartReport(File report) {
LOG.debug("Publish results");
long startTime = System.currentTimeMillis();
URL url;
try {
url = new URL(serverClient.getURL() + "/api/computation/submit_report?projectKey=" + project.getEffectiveKey());
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Invalid URL", e);
}
HttpRequest request = HttpRequest.post(url);
request.trustAllCerts();
request.trustAllHosts();
request.header("User-Agent", String.format("SonarQube %s", server.getVersion()));
request.basic(serverClient.getLogin(), serverClient.getPassword());
request.part("report", null, "application/octet-stream", report);
if (!request.ok()) {
int responseCode = request.code();
if (responseCode == 401) {
throw new IllegalStateException(String.format(serverClient.getMessageWhenNotAuthorized(), CoreProperties.LOGIN, CoreProperties.PASSWORD));
}
if (responseCode == 403) {
// SONAR-4397 Details are in response content
throw new IllegalStateException(request.body());
}
throw new IllegalStateException(String.format("Fail to execute request [code=%s, url=%s]: %s", responseCode, url, request.body()));
}
long stopTime = System.currentTimeMillis();
LOG.info("Analysis reports sent to server in " + (stopTime - startTime) + "ms");
}
代码示例来源:origin: com.restfuse/com.eclipsesource.restfuse
private void addAuthentication( HttpRequest request ) {
for( AuthenticationInfo authentication : authentications ) {
if( authentication.getType().equals( AuthenticationType.BASIC ) ) {
request.basic( authentication.getUser(), authentication.getPassword() );
} else if( authentication.getType().equals( AuthenticationType.DIGEST ) ) {
// TODO: implement digest auth
}
}
}
内容来源于网络,如有侵权,请联系作者删除!