tencent cloud

Feedback

Last updated: 2023-06-29 11:20:56
    The following code shows how to create QUIC requests with the iOS client. For details of the API description, see iOS APIs.

    Creating GET Requests

    // Session configuration
    TQUICURLSessionConfiguration *quicSessionConfiguration = [TQUICURLSessionConfiguration defaultConfiguration];
    // Congestion control algorithm
    quicSessionConfiguration.congestionType = TQUICCongestionTypeBBR;
    // Connection timeout
    quicSessionConfiguration.connectTimeoutMillis = 6 * 1000;
    // Create SessionManager. See %!s(<nil>) for instructions.
    TQUICHTTPSessionManager *quicSessionManager = [[TQUICHTTPSessionManager alloc] initWithSessionConfiguration:quicSessionConfiguration];
    // (Optional) Serialize via TQUICHTTPRequestSerializer/TQUICHTTPResponseSerializer. See %!s(<nil>) for instructions.
    
    // Initiate a GET request.
    [quicSessionManager GET:@"url"
    parameters:nil
    headers:nil
    timeoutInterval:0
    downloadProgress:nil
    success:^(TQUICURLSessionTask * _Nonnull task, id _Nullable responseObject) {
    // When the request is executed successfully, it returns the response data.
    // Get the response headers. Since this is an HTTP response, it can be converted into NSHTTPURLResponse.
    NSDictionary *headers = [(NSHTTPURLResponse *)task.response allHeaderFields];
    // Get the response body.
    id body = responseObject;
    } failure:^(TQUICURLSessionTask * _Nullable task, NSError * _Nonnull error) {
    // When the request fails to be executed, it returns the error message.
    NSInteger errorCode = error.code;
    }];

    Creating POST Requests

    // Session configuration
    TQUICURLSessionConfiguration *quicSessionConfiguration = [TQUICURLSessionConfiguration defaultConfiguration];
    // Congestion control algorithm
    quicSessionConfiguration.congestionType = TQUICCongestionTypeBBR;
    // Connection timeout
    quicSessionConfiguration.connectTimeoutMillis = 6 * 1000;
    // Create SessionManager. See %!s(<nil>) for instructions.
    TQUICHTTPSessionManager *quicSessionManager = [[TQUICHTTPSessionManager alloc] initWithSessionConfiguration:quicSessionConfiguration];
    // (Optional) Serialize via TQUICHTTPRequestSerializer/TQUICHTTPResponseSerializer. See %!s(<nil>) for instructions.
    
    // Construct body data.
    NSData *bodyData;
    // Initiate a POST request.
    [quicSessionManager POST:@"url"
    body:bodyData
    headers:nil
    timeoutInterval:timeInterval
    uploadProgress:^(NSProgress * _Nonnull uploadProgress) {
            
        } success:^(TQUICURLSessionTask * _Nonnull task, id  _Nullable responseObject) {
    // When the request is executed successfully, it returns the response data.
    // Get the response body.
    id body = responseObject;
    
        } failure:^(TQUICURLSessionTask * _Nullable task, NSError * _Nonnull error) {
    // When the request fails to be executed, it returns the error message.
    NSInteger errorCode = error.code;
    }];

    Canceling Requests

    // Create SessionManager.
    
    ...
    // Initiate a request via SessionDataTask. See %!s(<nil>) for instructions.
    TQUICURLSessionDataTask *dataTask =
    [quicSessionManager dataTaskWithRequest:request
                       uploadProgress:nil
                           downloadProgress:nil
                      completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
    
    // Run callback after the request has finished.
    
    }];
    
    //Send the request.
    [dataTask resume];
    
    //Cancel the request.
    [dataTask cancel];
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support