Configuring Preflight Requests for Cross-origin Access

Last updated: 2020-09-10 15:04:24

    Overview

    This document provides an overview of APIs and SDK sample codes related to preflight requests for cross-origin access.

    API Operation Name 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 Reference

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

    Configuring a Preflight Request for Cross-origin Access

    Feature 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";
    
    // Specify the domain the request that simuplates CORS comes from, request method and host
    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 "dir1/object1"
    request.object = @"exampleobject";
    
    [request setFinishBlock:^(id outputObject, NSError* error) {
        // outputObject returns information such as the Etag or custom headers
        NSDictionary* info = (NSDictionary *) outputObject;
    
    }];
    
    [[QCloudCOSXMLService defaultCOSXML] OptionsObject:request];

    Note:

    For more samples, please visit 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 "dir1/object1"
    optionsObject.object = "exampleobject";
    
    // Specify the domain the request that simuplates CORS comes from, request method and header
    optionsObject.origin = "http://www.qcloud.com";
    optionsObject.accessControlRequestMethod = "GET";
    optionsObject.accessControlRequestHeaders = "origin";
    
    // Bucket name in the format: `BucketName-APPID`
    optionsObject.bucket = "examplebucket-1250000000";
    
    optionsObject.finishBlock = {(result,error) in
    
      if let result = result {
           // “result" contains headers returned by the server
        }
    }
    QCloudCOSXMLService.defaultCOSXML().optionsObject(optionsObject);

    Note:

    For more samples, please visit GitHub.

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help