本文整理了Java中com.squareup.okhttp.HttpUrl.newBuilder()
方法的一些代码示例,展示了HttpUrl.newBuilder()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpUrl.newBuilder()
方法的具体详情如下:
包路径:com.squareup.okhttp.HttpUrl
类名称:HttpUrl
方法名:newBuilder
暂无
代码示例来源:origin: Javen205/IJPay
@Override
public String get(String url, Map<String, String> queryParas) {
com.squareup.okhttp.HttpUrl.Builder urlBuilder = com.squareup.okhttp.HttpUrl.parse(url).newBuilder();
for (Entry<String, String> entry : queryParas.entrySet()) {
urlBuilder.addQueryParameter(entry.getKey(), entry.getValue());
}
com.squareup.okhttp.HttpUrl httpUrl = urlBuilder.build();
com.squareup.okhttp.Request request = new com.squareup.okhttp.Request.Builder().url(httpUrl).get().build();
return exec(request);
}
代码示例来源:origin: blockchain/api-v1-client-java
private HttpUrl.Builder getHttpUrlBuilder(String baseURL, String resource) throws MalformedURLException {
HttpUrl url = HttpUrl.parse(baseURL);
if (url == null) {
throw new MalformedURLException();
}
HttpUrl.Builder urlBuilder = url.newBuilder();
urlBuilder.addPathSegment(resource);
return urlBuilder;
}
代码示例来源:origin: io.paradoxical/cassieq-client
static CassieqCredentials signedQueryString(String queryAuth) {
final Map<String, String> queryAuthParams =
Splitter.on('&')
.omitEmptyStrings()
.withKeyValueSeparator('=')
.split(queryAuth);
return request -> {
final HttpUrl httpUrl = request.httpUrl();
HttpUrl.Builder newUrlBuilder = httpUrl.newBuilder();
for (Map.Entry<String, String> entry : queryAuthParams.entrySet()) {
newUrlBuilder = newUrlBuilder.addQueryParameter(entry.getKey(), entry.getValue());
}
return request.newBuilder()
.url(newUrlBuilder.build())
.build();
};
}
代码示例来源:origin: com.jfinal/jfinal-weixin
@Override
public String get(String url, Map<String, String> queryParas) {
com.squareup.okhttp.HttpUrl.Builder urlBuilder = com.squareup.okhttp.HttpUrl.parse(url).newBuilder();
for (Entry<String, String> entry : queryParas.entrySet()) {
urlBuilder.addQueryParameter(entry.getKey(), entry.getValue());
}
com.squareup.okhttp.HttpUrl httpUrl = urlBuilder.build();
com.squareup.okhttp.Request request = new com.squareup.okhttp.Request.Builder().url(httpUrl).get().build();
return exec(request);
}
代码示例来源:origin: com.github.javen205/IJPay
@Override
public String get(String url, Map<String, String> queryParas) {
com.squareup.okhttp.HttpUrl.Builder urlBuilder = com.squareup.okhttp.HttpUrl.parse(url).newBuilder();
for (Entry<String, String> entry : queryParas.entrySet()) {
urlBuilder.addQueryParameter(entry.getKey(), entry.getValue());
}
com.squareup.okhttp.HttpUrl httpUrl = urlBuilder.build();
com.squareup.okhttp.Request request = new com.squareup.okhttp.Request.Builder().url(httpUrl).get().build();
return exec(request);
}
代码示例来源:origin: PaNaVTEC/Clean-Contacts
private HttpUrl composeUrl(Chain chain) {
return chain.request().httpUrl()
.newBuilder()
.addQueryParameter("seed", "panavtec")
.build();
}
}
代码示例来源:origin: com.netflix.spinnaker.clouddriver/clouddriver-artifacts
public InputStream download(Artifact artifact) throws IOException {
HttpUrl.Builder fileUrl;
try {
fileUrl = HttpUrl.parse(artifact.getReference()).newBuilder();
} catch (Exception e) {
throw new IllegalArgumentException("Malformed Bitbucket content URL in 'reference'. Read more here https://www.spinnaker.io/reference/artifacts/types/bitbucket-file/: " + e.getMessage(), e);
}
Request downloadRequest = requestBuilder
.url(artifact.getReference())
.build();
try {
Response downloadResponse = okHttpClient.newCall(downloadRequest).execute();
return downloadResponse.body().byteStream();
} catch (IOException e) {
throw new FailedDownloadException("Unable to download the contents of artifact " + artifact + ": " + e.getMessage(), e);
}
}
代码示例来源:origin: org.sonarsource.sonarqube/sonar-batch
@VisibleForTesting
void logSuccess(@Nullable String taskId) {
if (taskId == null) {
LOG.info("ANALYSIS SUCCESSFUL");
} else {
Map<String, String> metadata = new LinkedHashMap<>();
String effectiveKey = projectReactor.getRoot().getKeyWithBranch();
metadata.put("projectKey", effectiveKey);
metadata.put("serverUrl", publicUrl());
URL dashboardUrl = HttpUrl.parse(publicUrl()).newBuilder()
.addPathSegment("dashboard").addPathSegment("index").addPathSegment(effectiveKey)
.build()
.url();
metadata.put("dashboardUrl", dashboardUrl.toExternalForm());
URL taskUrl = HttpUrl.parse(publicUrl()).newBuilder()
.addPathSegment("api").addPathSegment("ce").addPathSegment("task")
.addQueryParameter("id", taskId)
.build()
.url();
metadata.put("ceTaskId", taskId);
metadata.put("ceTaskUrl", taskUrl.toExternalForm());
LOG.info("ANALYSIS SUCCESSFUL, you can browse {}", dashboardUrl);
LOG.info("Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report");
LOG.info("More about the report processing at {}", taskUrl);
dumpMetadata(metadata);
}
}
代码示例来源:origin: com.netflix.spinnaker.clouddriver/clouddriver-artifacts
public InputStream download(Artifact artifact) throws IOException {
HttpUrl.Builder fileUrl;
try {
// reference should use the Gitlab raw file download url: https://docs.gitlab.com/ee/api/repository_files.html#get-raw-file-from-repository
fileUrl = HttpUrl.parse(artifact.getReference()).newBuilder();
} catch (Exception e) {
throw new IllegalArgumentException("Malformed gitlab content URL in 'reference'. Read more here https://www.spinnaker.io/reference/artifacts/types/gitlab-file/: " + e.getMessage(), e);
}
String version = artifact.getVersion();
if (StringUtils.isEmpty(version)) {
log.info("No version specified for artifact {}, using 'master'.", version);
version = "master";
}
fileUrl.addQueryParameter("ref", version);
Request fileRequest = requestBuilder
.url(fileUrl.build().toString())
.build();
try {
Response downloadResponse = okHttpClient.newCall(fileRequest).execute();
return downloadResponse.body().byteStream();
} catch (IOException e) {
throw new com.netflix.spinnaker.clouddriver.artifacts.gitlab.GitlabArtifactCredentials.FailedDownloadException("Unable to download the contents of artifact " + artifact + ": " + e.getMessage(), e);
}
}
代码示例来源:origin: com.netflix.spinnaker.clouddriver/clouddriver-artifacts
public InputStream download(Artifact artifact) throws IOException {
HttpUrl.Builder metadataUrlBuilder;
try {
metadataUrlBuilder = HttpUrl.parse(artifact.getReference()).newBuilder();
} catch (Exception e) {
throw new IllegalArgumentException("Malformed github content URL in 'reference'. Read more here https://www.spinnaker.io/reference/artifacts/types/github-file/: " + e.getMessage(), e);
代码示例来源:origin: greenaddress/GreenBits
@Override
public InetSocketAddress[] getPeers(long services, long timeoutValue, TimeUnit timeoutUnit) throws PeerDiscoveryException {
try {
HttpUrl.Builder url = HttpUrl.get(details.uri).newBuilder();
if (services != 0)
url.addQueryParameter("srvmask", Long.toString(services));
Request.Builder request = new Request.Builder();
request.url(url.build());
request.addHeader("User-Agent", VersionMessage.LIBRARY_SUBVER); // TODO Add main version.
log.info("Requesting seeds from {}", url);
Response response = client.newCall(request.build()).execute();
if (!response.isSuccessful())
throw new PeerDiscoveryException("HTTP request failed: " + response.code() + " " + response.message());
InputStream stream = response.body().byteStream();
GZIPInputStream zip = new GZIPInputStream(stream);
PeerSeedProtos.SignedPeerSeeds proto = PeerSeedProtos.SignedPeerSeeds.parseDelimitedFrom(zip);
stream.close();
return protoToAddrs(proto);
} catch (PeerDiscoveryException e1) {
throw e1;
} catch (Exception e) {
throw new PeerDiscoveryException(e);
}
}
代码示例来源:origin: HashEngineering/dashj
@Override
public InetSocketAddress[] getPeers(long services, long timeoutValue, TimeUnit timeoutUnit) throws PeerDiscoveryException {
try {
HttpUrl.Builder url = HttpUrl.get(details.uri).newBuilder();
if (services != 0)
url.addQueryParameter("srvmask", Long.toString(services));
Request.Builder request = new Request.Builder();
request.url(url.build());
request.addHeader("User-Agent", VersionMessage.LIBRARY_SUBVER); // TODO Add main version.
log.info("Requesting seeds from {}", url);
Response response = client.newCall(request.build()).execute();
if (!response.isSuccessful())
throw new PeerDiscoveryException("HTTP request failed: " + response.code() + " " + response.message());
InputStream stream = response.body().byteStream();
GZIPInputStream zip = new GZIPInputStream(stream);
PeerSeedProtos.SignedPeerSeeds proto;
try {
proto = PeerSeedProtos.SignedPeerSeeds.parseDelimitedFrom(zip);
} finally {
zip.close(); // will close InputStream as well
}
return protoToAddrs(proto);
} catch (PeerDiscoveryException e1) {
throw e1;
} catch (Exception e) {
throw new PeerDiscoveryException(e);
}
}
代码示例来源:origin: cash.bitcoinj/bitcoinj-core
@Override
public InetSocketAddress[] getPeers(long services, long timeoutValue, TimeUnit timeoutUnit) throws PeerDiscoveryException {
try {
HttpUrl.Builder url = HttpUrl.get(details.uri).newBuilder();
if (services != 0)
url.addQueryParameter("srvmask", Long.toString(services));
Request.Builder request = new Request.Builder();
request.url(url.build());
request.addHeader("User-Agent", VersionMessage.LIBRARY_SUBVER); // TODO Add main version.
log.info("Requesting seeds from {}", url);
Response response = client.newCall(request.build()).execute();
if (!response.isSuccessful())
throw new PeerDiscoveryException("HTTP request failed: " + response.code() + " " + response.message());
InputStream stream = response.body().byteStream();
GZIPInputStream zip = new GZIPInputStream(stream);
PeerSeedProtos.SignedPeerSeeds proto;
try {
proto = PeerSeedProtos.SignedPeerSeeds.parseDelimitedFrom(zip);
} finally {
zip.close(); // will close InputStream as well
}
return protoToAddrs(proto);
} catch (PeerDiscoveryException e1) {
throw e1;
} catch (Exception e) {
throw new PeerDiscoveryException(e);
}
}
内容来源于网络,如有侵权,请联系作者删除!