//Create QuicClient and initialize QUIC configuration. It is recommended to use QuicClient as a global variable. For more information about the API, see %!s(<nil>).QuicClient quicClient = new QuicClient.Builder().setCongestionType(QuicClient.CONGESTION_TYPE_BBR) //Use BBR algorithm..setConnectTimeoutMillis(6 * 1000) //Configure connection timeout..build();//Create QuicRequest and specify the request URL.String url="";QuicRequest request = new QuicRequest.Builder(url).get().build();//Execute the request asynchronously and get the result. See %!s(<nil>) for instructions.quicClient.newCall(request).enqueue(new QuicCallback() {@Overridepublic void onResponse(QuicCall call, QuicResponse response) throws IOException {//When the request is executed successfully, it returns the response data.ResponseBody body = response.body();if(body != null) {String res = body.string();}}@Overridepublic void onFailed(QuicCall call, int errorCode, String error) {//When the request fails to be executed, it returns the error message.}});
//Create QuicClient and initialize QUIC configuration. It is recommended to use QuicClient as a global variable. For detailed steps, see %!s(<nil>).QuicClient quicClient = new QuicClient.Builder().setCongestionType(QuicClient.CONGESTION_TYPE_BBR) //Use BBR algorithm..setConnectTimeoutMillis(3 * 1000) //Configure connection timeout..build();//Construct body data.String body="your body string";RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), body);//Create QuicRequest.String url="";QuicRequest request = new QuicRequest.Builder(url).post(requestBody).build();//Execute the request asynchronously and get the result. See %!s(<nil>) for instructions.quicClient.newCall(request).enqueue(new QuicCallback() {@Overridepublic void onResponse(QuicCall call, QuicResponse response) throws IOException {//When the request is executed successfully, it returns the response data.ResponseBody body = response.body();if(body != null) {String res = body.string();}}@Overridepublic void onFailed(QuicCall call, int errorCode, String error) {//When the request fails to be executed, it returns the error message.}});
...//Create QuicCall. See %!s(<nil>) for instructions.QuicCall quicCall = quicClient.newCall(request);// Initiate a request....//Cancel the request using the cancel method via QuicCall.quicCall.cancel();
Was this page helpful?