QuicClient quicClient = new QuicClient.Builder().setCongestionType(QuicClient.CONGESTION_TYPE_BBR) //使用BBR拥塞算法.setConnectTimeoutMillis(6 * 1000) //配置连接超时时间.build();//创建QuicRequest,配置请求urlString url="";QuicRequest request = new QuicRequest.Builder(url).get().build();quicClient.newCall(request).enqueue(new QuicCallback() {@Overridepublic void onResponse(QuicCall call, QuicResponse response) throws IOException {//请求执行成功,获取响应数据ResponseBody body = response.body();if(body != null) {String res = body.string();}}@Overridepublic void onFailed(QuicCall call, int errorCode, String error) {//请求执行失败,返回错误信息}});
QuicClient quicClient = new QuicClient.Builder().setCongestionType(QuicClient.CONGESTION_TYPE_BBR) //使用BBR拥塞算法.setConnectTimeoutMillis(3 * 1000) //配置连接超时时间.build();//构造body数据String body="your body string";RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), body);//创建QuicRequestString url="";QuicRequest request = new QuicRequest.Builder(url).post(requestBody).build();quicClient.newCall(request).enqueue(new QuicCallback() {@Overridepublic void onResponse(QuicCall call, QuicResponse response) throws IOException {//请求执行成功,获取响应数据ResponseBody body = response.body();if(body != null) {String res = body.string();}}@Overridepublic void onFailed(QuicCall call, int errorCode, String error) {//请求执行失败,返回错误信息}});
...QuicCall quicCall = quicClient.newCall(request);//发起请求...//通过QuicCall中的cancel方法请取消请求quicCall.cancel();
本页内容是否解决了您的问题?