okhttp3.Call.request()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(224)

本文整理了Java中okhttp3.Call.request()方法的一些代码示例,展示了Call.request()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Call.request()方法的具体详情如下:
包路径:okhttp3.Call
类名称:Call
方法名:request

Call.request介绍

[英]Returns the original request that initiated this call.
[中]返回发起此调用的原始请求。

代码示例

代码示例来源:origin: square/okhttp

@Override
public void callStart(Call call) {
 startNs = System.nanoTime();
 logWithTime("callStart: " + call.request());
}

代码示例来源:origin: square/okhttp

@Override public EventListener create(Call call) {
  long callId = nextCallId.getAndIncrement();
  System.out.printf("%04d %s%n", callId, call.request().url());
  return new PrintingEventListener(callId, System.nanoTime());
 }
};

代码示例来源:origin: square/retrofit

@Override public synchronized Request request() {
 okhttp3.Call call = rawCall;
 if (call != null) {
  return call.request();
 }
 if (creationFailure != null) {
  if (creationFailure instanceof IOException) {
   throw new RuntimeException("Unable to create request.", creationFailure);
  } else if (creationFailure instanceof RuntimeException) {
   throw (RuntimeException) creationFailure;
  } else {
   throw (Error) creationFailure;
  }
 }
 try {
  return (rawCall = createRawCall()).request();
 } catch (RuntimeException | Error e) {
  throwIfFatal(e); // Do not assign a fatal error to creationFailure.
  creationFailure = e;
  throw e;
 } catch (IOException e) {
  creationFailure = e;
  throw new RuntimeException("Unable to create request.", e);
 }
}

代码示例来源:origin: com.squareup.okhttp3/logging-interceptor

@Override
public void callStart(Call call) {
 startNs = System.nanoTime();
 logWithTime("callStart: " + call.request());
}

代码示例来源:origin: com.squareup.retrofit2/retrofit

@Override public synchronized Request request() {
 okhttp3.Call call = rawCall;
 if (call != null) {
  return call.request();
 }
 if (creationFailure != null) {
  if (creationFailure instanceof IOException) {
   throw new RuntimeException("Unable to create request.", creationFailure);
  } else if (creationFailure instanceof RuntimeException) {
   throw (RuntimeException) creationFailure;
  } else {
   throw (Error) creationFailure;
  }
 }
 try {
  return (rawCall = createRawCall()).request();
 } catch (RuntimeException | Error e) {
  throwIfFatal(e); // Do not assign a fatal error to creationFailure.
  creationFailure = e;
  throw e;
 } catch (IOException e) {
  creationFailure = e;
  throw new RuntimeException("Unable to create request.", e);
 }
}

代码示例来源:origin: square/okhttp

networkInterceptor.proceed();
OutputStreamRequestBody requestBody = (OutputStreamRequestBody) call.request().body();
if (requestBody != null) requestBody.outputStream().close();

代码示例来源:origin: jeasonlzy/okhttp-OkGo

/** 根据Tag取消请求 */
public static void cancelTag(OkHttpClient client, Object tag) {
  if (client == null || tag == null) return;
  for (Call call : client.dispatcher().queuedCalls()) {
    if (tag.equals(call.request().tag())) {
      call.cancel();
    }
  }
  for (Call call : client.dispatcher().runningCalls()) {
    if (tag.equals(call.request().tag())) {
      call.cancel();
    }
  }
}

代码示例来源:origin: jeasonlzy/okhttp-OkGo

/** 根据Tag取消请求 */
public void cancelTag(Object tag) {
  if (tag == null) return;
  for (Call call : getOkHttpClient().dispatcher().queuedCalls()) {
    if (tag.equals(call.request().tag())) {
      call.cancel();
    }
  }
  for (Call call : getOkHttpClient().dispatcher().runningCalls()) {
    if (tag.equals(call.request().tag())) {
      call.cancel();
    }
  }
}

代码示例来源:origin: square/okhttp

@Override public OutputStream getOutputStream() throws IOException {
 OutputStreamRequestBody requestBody = (OutputStreamRequestBody) buildCall().request().body();
 if (requestBody == null) {
  throw new ProtocolException("method does not support a request body: " + method);
 }
 // If this request needs to stream bytes to the server, build a physical connection immediately
 // and start streaming those bytes over that connection.
 if (requestBody instanceof StreamedRequestBody) {
  connect();
  networkInterceptor.proceed();
 }
 if (requestBody.isClosed()) {
  throw new ProtocolException("cannot write request body after response has been read");
 }
 return requestBody.outputStream();
}

代码示例来源:origin: tianshaojie/AndroidFine

@Override
  public void onFailure(Call call, IOException e) {
    handler.sendFailureMessage(call.request(), e);
  }
});

代码示例来源:origin: tianshaojie/AndroidFine

@Override
  public void onFailure(Call call, IOException e) {
    handler.sendFailureMessage(call.request(), e);
  }
});

代码示例来源:origin: tianshaojie/AndroidFine

@Override
public void onResponse(Call call, Response response) {
  try {
    RestApiResponse apiResponse = getRestApiResponse(response.body().toString());
    handler.sendSuccessMessage(apiResponse);
  } catch (Exception e) {
    handler.sendFailureMessage(call.request(), e);
  }
}

代码示例来源:origin: tianshaojie/AndroidFine

@Override
public void onResponse(Call call, Response response) {
  try {
    RestApiResponse apiResponse = getRestApiResponse(response.body().toString());
    handler.sendSuccessMessage(apiResponse);
  } catch (Exception e) {
    handler.sendFailureMessage(call.request(), e);
  }
}

代码示例来源:origin: dongjunkun/GanK

/**
 * 根据tag取消请求
 *
 * @param tag 标签
 */
public static void cancelRequest(Object tag) {
  for (Call call : okHttpClient.dispatcher().queuedCalls()) {
    if (call.request().tag().equals(tag)) {
      call.cancel();
    }
  }
  for (Call call : okHttpClient.dispatcher().runningCalls()) {
    if (call.request().tag().equals(tag)) {
      call.cancel();
    }
  }
}

代码示例来源:origin: limedroid/XDroid

@Override
public void onError(Call call, Exception e, int id) {
  if (e != null) {
    if (e instanceof UnknownHostException
        && expireTime > -1) {
      //无网络连接
      String cacheKey = getCacheKey(call.request());
      String cacheContent = DiskCache.getInstance(App.getContext()).get(cacheKey);
      if (!TextUtils.isEmpty(cacheContent)) {
        try {
          if (entityClass == String.class) {
            onResponse((T) cacheContent, id);
            return;
          }
          T model = GsonProvider.getInstance().getGson().fromJson(cacheContent, entityClass);
          onResponse(model, id);
          return;
        } catch (Exception exception) {
        }
      }
    }
  }
  onFail(call, e, id);
}

代码示例来源:origin: stackoverflow.com

@Override
public void onResponse(Call call, final Response response) throws IOException {
   if(response.isSuccessful()) {
     String responseString = response.body().string();                                   
     postSuccess(listener, (String)call.request().tag(), responseString);
   }
   else {               
    String errorBodyString = response.body().string();                  
    postFailure(listener, (String)call.request().tag(),response.code()+","+errorBodyString);
   }
}

代码示例来源:origin: ApolloAuto/apollo-DuerOS

@Override
  public void onFailure(Call call, final IOException e) {
    errorCallback(callback, call.request().url().toString(), e.toString());
  }
});

代码示例来源:origin: watson-developer-cloud/java-sdk

@Override
public ServiceCall<T> addHeader(String name, String value) {
 Request.Builder builder = call.request().newBuilder();
 builder.header(name, value);
 call = client.newCall(builder.build());
 return this;
}

代码示例来源:origin: ApolloAuto/apollo-DuerOS

@Override
public void onFailure(Call call, final IOException e) {
  e.printStackTrace();
  downloadErrorCallback(downloadCallback, call.request().url().toString(), e.toString());
}

代码示例来源:origin: com.ibm.watson.developer_cloud/core

@Override
 protected void finalize() throws Throwable {
  super.finalize();
  if (!call.isExecuted()) {
   final Request r = call.request();
   LOG.warning(r.method() + " request to " + r.url() + " has not been sent. Did you forget to call execute()?");
  }
 }
}

相关文章