本文整理了Java中com.squareup.okhttp.Request.urlString
方法的一些代码示例,展示了Request.urlString
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.urlString
方法的具体详情如下:
包路径:com.squareup.okhttp.Request
类名称:Request
方法名:urlString
暂无
代码示例来源:origin: facebook/stetho
@Override
public String url() {
return mRequest.urlString();
}
代码示例来源:origin: facebook/stetho
@Override
public String url() {
return mRequest.urlString();
}
代码示例来源:origin: stackoverflow.com
private static class UrlInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
String url = request.urlString();
Log.d(TAG, url);
Response response = chain.proceed(request);
return response;
}
}
代码示例来源:origin: com.squareup.okhttp/okhttp-ws
static RealWebSocket create(StreamAllocation streamAllocation, Response response,
Random random, WebSocketListener listener) {
String url = response.request().urlString();
ThreadPoolExecutor replyExecutor =
new ThreadPoolExecutor(1, 1, 1, SECONDS, new LinkedBlockingDeque<Runnable>(),
Util.threadFactory(String.format("OkHttp %s WebSocket", url), true));
replyExecutor.allowCoreThreadTimeOut(true);
return new StreamWebSocket(streamAllocation, random, replyExecutor, listener, url);
}
代码示例来源:origin: fire3/sailorcast
public static void asyncGet(Request request, Callback callback) {
Log.d("fire3", "async request Url: " + request.urlString());
SailorCast.getHttpClient().newCall(request).enqueue(callback);
}
代码示例来源:origin: com.stanfy.helium/helium
private static String getRequestInfo(final Request request, final Response response) {
final StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("\nRequest info: ");
stringBuilder.append(request.method())
.append(' ')
.append(request.urlString())
.append('\n');
dumpHeaders(request.headers(), stringBuilder);
if (request.body() != null) {
final String loggedEntity = requestBodyToString(request.body());
if (loggedEntity != null) {
stringBuilder.append('\n').append(loggedEntity).append('\n');
}
}
stringBuilder.append('\n');
if (response == null) {
stringBuilder.append("Response info is not available.");
} else {
stringBuilder.append("Response info:\n")
.append(response.code()).append(" ").append(response.message()).append("\n");
dumpHeaders(response.headers(), stringBuilder);
stringBuilder
.append('\n')
.append(responseBodyToString(response.body())).append('\n');
}
return stringBuilder.toString();
}
代码示例来源:origin: blockchain/api-v1-client-java
private String makeRequest(Request request) throws IOException {
Response response = getOkHttpClientInstance().newCall(request).execute();
if (isNotSuccessfulResponse(response))
throw new IOException(String.format("Unsuccessful call to %s Response: %s",
request.urlString(),
response));
return response.body().string();
}
代码示例来源:origin: org.graylog2/graylog2-radio
public void ping() throws IOException {
final PingRequest pingRequest = PingRequest.create(ourUri.toString());
final URI uri = serverUri.resolve("/system/radios/" + nodeId + "/ping");
final Request request = new Request.Builder()
.url(uri.toURL())
.put(RequestBody.create(CONTENT_TYPE, objectMapper.writeValueAsBytes(pingRequest)))
.build();
final Response r = httpClient.newCall(request).execute();
// fail on a non-ok status
if (!r.isSuccessful()) {
throw new RuntimeException("Expected successful HTTP response [2xx] but got [" + r.code() + "]. Request was " + request.urlString());
}
}
代码示例来源:origin: tomahawk-player/tomahawk-android
public JsonElement get(JsonObject object, String memberName) throws IOException {
JsonElement element = object.get(memberName);
if (element == null) {
JsonObject links = object.getAsJsonObject("links");
if (links != null && links.has(memberName)) {
Request request = new Request.Builder()
.url(HATCHET_BASE_URL + links.get(memberName).getAsString())
.build();
Log.d(TAG, "following link: " + request.urlString());
Response response = mOkHttpClient.newCall(request).execute();
if (!response.isSuccessful()) {
throw new IOException("API request with URL '" + request.urlString()
+ "' not successful. Code was " + response.code());
}
try {
element = GsonHelper.get().fromJson(
response.body().charStream(), JsonElement.class);
} catch (JsonIOException | JsonSyntaxException e) {
throw new IOException(e);
} finally {
response.body().close();
}
}
}
return element;
}
}
代码示例来源:origin: fire3/sailorcast
public static String syncGet(String url) {
Request request = buildRequest(url);
Log.d("fire3", "sync request Url: " + request.urlString());
try {
Response response = SailorCast.getHttpClient().newCall(request).execute();
if (response.code() == 200) {
String ret = new String(response.body().bytes(), "utf-8");
return ret;
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
代码示例来源:origin: fire3/sailorcast
public static void asyncGet(Request request, final Activity activity, final Callback callback) {
Log.d("fire3", "async request Url: " + request.urlString());
SailorCast.getHttpClient().newCall(request).enqueue(new Callback() {
Handler mainHandler = new Handler(activity.getMainLooper());
@Override
public void onFailure(final Request request, final IOException e) {
mainHandler.post(new Runnable() {
@Override
public void run() {
callback.onFailure(request,e);
}
});
}
@Override
public void onResponse(final Response response) throws IOException {
mainHandler.post(new Runnable() {
@Override
public void run() {
try {
callback.onResponse(response);
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
});
}
代码示例来源:origin: com.stanfy.helium/helium
public static void assertCorrectEntity(final TypedEntity entity, final Response response) {
if (entity.getValidationError() != null) {
Request request = response.request();
throw failure(
request.method() + " " + request.urlString() + "\n"
+ "--------- Validation problems ---------\n"
+ entity.getValidationError(),
request, response
);
}
}
代码示例来源:origin: blockchain/thunder
/**
* This method makes a get request to a specific API resource.
* Request is built using the OkHttp {@link HttpUrl} builder.
*
* @param resource The API resource being requested.
* @param params A set of params sent to the resource
* @return Returns a response as a {@link String}
* @throws IOException Thrown if the request was unsuccessful.
*/
@Override
public String get (String resource, Map<String, String> params) throws APIException, IOException {
HttpUrl.Builder url = getHttpUrlBuilder(resource);
for (String paramName : params.keySet()) {
url.addEncodedQueryParameter(paramName, params.get(paramName));
}
Request request = new Request.Builder()
.url(url.build())
.build();
Response response = getOkHttpClientInstance().newCall(request).execute();
if (isNotSuccessfulResponse(response)) {
throw new IOException(String.format("Unsuccessful call to %s Response: %s",
request.urlString(),
response));
}
return response.body().string();
}
代码示例来源:origin: com.squareup.retrofit/retrofit
static Response parseResponse(com.squareup.okhttp.Response response) {
return new Response(response.request().urlString(), response.code(), response.message(),
createHeaders(response.headers()), createResponseBody(response.body()));
}
代码示例来源:origin: spinnaker/fiat
@Override
public Response intercept(Chain chain) throws IOException {
ExponentialBackOff backoff = new ExponentialBackOff();
backoff.setMaxElapsedTime(maxElapsedBackoffMs);
BackOffExecution backOffExec = backoff.start();
Response response = null;
long waitTime = 0;
while (waitTime != BackOffExecution.STOP) {
Request request = chain.request();
response = chain.proceed(request);
if (response.isSuccessful() ||
NON_RETRYABLE_METHODS.contains(request.method()) ||
response.code() == 404) {
return response;
}
try {
waitTime = backOffExec.nextBackOff();
if (waitTime != BackOffExecution.STOP) {
response.body().close();
log.warn("Request for " + request.urlString() + " failed. Backing off for " + waitTime + "ms");
Thread.sleep(waitTime);
}
} catch (Throwable ignored) {
break;
}
}
return response;
}
}
代码示例来源:origin: blockchain/thunder
/**
* This method makes a post request to a specific API resource.
* Request is built using the OkHttp {@link HttpUrl} builder.
* Request body is built using the OkHttp {@link FormEncodingBuilder} builder .
*
* @param resource The API resource being requested.
* @param params A set of params sent to the resource
* @return Returns a response as a {@link String}
* @throws IOException Thrown if the request was unsuccessful.
*/
@Override
public String post (String resource, Map<String, String> params) throws APIException, IOException {
HttpUrl.Builder url = getHttpUrlBuilder(resource);
FormEncodingBuilder formEncodingBuilder = new FormEncodingBuilder();
for (String paramName : params.keySet()) {
formEncodingBuilder.addEncoded(paramName, params.get(paramName));
}
Request request = new Request.Builder()
.url(url.build())
.post(formEncodingBuilder.build())
.build();
Response response = getOkHttpClientInstance().newCall(request).execute();
if (isNotSuccessfulResponse(response)) {
throw new IOException(String.format("Unsuccessful call to %s Response: %s",
request.urlString(),
response));
}
return response.body().string();
}
代码示例来源:origin: com.stanfy.helium/helium
@Override
public Response intercept(final Chain chain) throws IOException {
Request request = chain.request();
LOG.info("---> HTTP {} {}", request.method(), request.urlString());
logHeaders(request.headers());
if (request.body() != null) {
long time = System.currentTimeMillis() - start;
LOG.info("<--- HTTP {} {} ({}ms)", request.urlString(), response.code(), time);
logHeaders(response.headers());
BufferedSource source = response.body().source();
代码示例来源:origin: com.palantir.remoting2/tracing-okhttp2
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
// instrument request
OpenSpan callState = Tracer.startSpan(request.method() + " " + request.urlString(), SpanType.CLIENT_OUTGOING);
Request.Builder instrumentedRequest = new Request.Builder()
.headers(request.headers())
.url(request.url())
.method(request.method(), request.body())
.header(TraceHttpHeaders.TRACE_ID, Tracer.getTraceId())
.header(TraceHttpHeaders.SPAN_ID, callState.getSpanId())
.header(TraceHttpHeaders.IS_SAMPLED, Tracer.isTraceObservable() ? "1" : "0");
if (callState.getParentSpanId().isPresent()) {
instrumentedRequest.header(TraceHttpHeaders.PARENT_SPAN_ID, callState.getParentSpanId().get());
}
Response response;
try {
response = chain.proceed(instrumentedRequest.build());
} finally {
Tracer.completeSpan();
}
return response;
}
}
内容来源于网络,如有侵权,请联系作者删除!