tencent cloud

masukan

Configuring CORS Preflight Requests

Terakhir diperbarui:2021-11-30 12:37:31

    Overview

    This document provides an overview of APIs and SDK code samples related to CORS preflight requests.

    API Operation Description
    Options Object 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.intl.cloud.tencent.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.

    Hubungi Kami

    Hubungi tim penjualan atau penasihat bisnis kami untuk membantu bisnis Anda.

    Dukungan Teknis

    Buka tiket jika Anda mencari bantuan lebih lanjut. Tiket kami tersedia 7x24.

    Dukungan Telepon 7x24