tencent cloud

Feedback

Configuring CORS Preflight Requests

Last updated: 2024-01-23 17:15:08

    Overview

    This document provides an overview of APIs and SDK code samples related to CORS preflight requests.
    API
    Operation
    Description
    Configuring a preflight request for cross-origin access
    Sends a preflight request to check whether a real cross-origin access request can be sent

    SDK API References

    For parameters and method description of all APIs in the SDK, please see SDK API Reference.

    Configuring a Preflight Request for Cross-origin Access

    Description

    This API is used to get the cross-origin access configuration for a preflight request.

    Sample code

    Objective-C
    QCloudOptionsObjectRequest* request = [[QCloudOptionsObjectRequest alloc] init];
    
    // Bucket name in the format: `BucketName-APPID`
    request.bucket =@"examplebucket-1250000000";
    
    // Set the origin domain, request method, and host for the CORS pre-flight request.
    request.origin = @"http://cloud.tencent.com";
    request.accessControlRequestMethod = @"GET";
    request.accessControlRequestHeaders = @"host";
    
    // Object key, i.e. the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"
    request.object = @"exampleobject";
    
    [request setFinishBlock:^(id outputObject, NSError* error) {
    // outputObject contains information such as the ETag or custom headers in the response.
    NSDictionary* info = (NSDictionary *) outputObject;
    
    }];
    
    [[QCloudCOSXMLService defaultCOSXML] OptionsObject:request];
    Note:
    For the complete sample, go to GitHub.
    Swift
    let optionsObject = QCloudOptionsObjectRequest.init();
    
    // Object key, i.e. the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"
    optionsObject.object = "exampleobject";
    
    // Set the origin domain, request method, and headers for the CORS pre-flight request.
    optionsObject.origin = "http://www.qcloud.com";
    optionsObject.accessControlRequestMethod = "GET";
    optionsObject.accessControlRequestHeaders = "origin";
    
    // Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
    optionsObject.bucket = "examplebucket-1250000000";
    
    optionsObject.finishBlock = {(result,error) in
    if let result = result {
    // You can get the header information returned by the server from `result`
    }
    }
    QCloudCOSXMLService.defaultCOSXML().optionsObject(optionsObject);
    Note:
    For the complete sample, go to GitHub.
    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