更新时间:2023-11-08 gmt 08:00
设置托管配置-j9九游会登录
您可以通过setbucketwebsite设置桶的托管配置。
配置默认j9九游会登录主页和错误页面
以下代码展示了如何配置默认j9九游会登录主页和错误页面:
static obsclient *client;
nsstring *endpoint = @"your-endpoint";
// 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全;本示例以ak和sk保存在环境变量中为例,运行本示例前请先在本地环境中设置环境变量accesskeyid和secretaccesskey。
// 您可以登录访问管理控制台获取访问密钥ak/sk,获取方式请参见https://support.huaweicloud.com/usermanual-ca/ca_01_0003.html
char* ak_env = getenv("accesskeyid");
char* sk_env = getenv("secretaccesskey");
nsstring *ak = [nsstring stringwithutf8string:ak_env];
nsstring *sk = [nsstring stringwithutf8string:sk_env];
// 初始化身份验证
obsstaticcredentialprovider *credentialprovider = [[obsstaticcredentialprovider alloc] initwithaccesskey:ak secretkey:sk];
//初始化服务配置
obsserviceconfiguration *conf = [[obsserviceconfiguration alloc] initwithurlstring:endpoint credentialprovider:credentialprovider];
// 初始化client
client = [[obsclient alloc] initwithconfiguration:conf];
obswebsiteconfcustom* redirectcustom = [obswebsiteconfcustom new];
// 配置默认j9九游会登录主页
obswebsiteconfcustomindexdocument* indexdocument = [[obswebsiteconfcustomindexdocument alloc]initwithsuffix:@"index.html"];
// 配置默认错误界面
obswebsiteconfcustomerrordocument* errordocument = [[obswebsiteconfcustomerrordocument alloc]initwithkey:@"error.html"];
obswebsiteconfcustomroutingrule* redirectrule = [obswebsiteconfcustomroutingrule new];
obswebsiteconfcustomcondition* condition = [obswebsiteconfcustomcondition new];
condition.keyprefixequals = @"docs/";
// condition.httperrorcodereturnedequals = @"404";
// 配置重定向规则
obswebsiteconfcustomredirect* redirect = [obswebsiteconfcustomredirect new];
redirect.replacekeyprefixwith = @"documents/";
redirect.protocol = @"http";
redirect.hostname = @"url";
// redirect.replacekeywith = @"error.html";
redirect.httpredirectcode = @"301";
redirectrule.condition = condition;
redirectrule.redirect = redirect;
[redirectcustom.indexdocumentlist addobject:indexdocument];
[redirectcustom.errordocumentlist addobject:errordocument];
[redirectcustom.routingruleslist addobject:redirectrule];
obssetbucketwebsiterequest *request = [[obssetbucketwebsiterequest alloc]initwithbucketname:@"bucketname" configuration:redirectcustom];
[client setbucketwebsite:request completionhandler:^(obssetbucketwebsiteresponse *response, nserror *error){
nslog(@"%@",response);
}];
配置所有请求重定向
以下代码展示了如何配置所有请求重定向:
static obsclient *client;
nsstring *endpoint = @"your-endpoint";
// 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全;本示例以ak和sk保存在环境变量中为例,运行本示例前请先在本地环境中设置环境变量accesskeyid和secretaccesskey。
// 您可以登录访问管理控制台获取访问密钥ak/sk,获取方式请参见https://support.huaweicloud.com/usermanual-ca/ca_01_0003.html
char* ak_env = getenv("accesskeyid");
char* sk_env = getenv("secretaccesskey");
nsstring *ak = [nsstring stringwithutf8string:ak_env];
nsstring *sk = [nsstring stringwithutf8string:sk_env];
// 初始化身份验证
obsstaticcredentialprovider *credentialprovider = [[obsstaticcredentialprovider alloc] initwithaccesskey:ak secretkey:sk];
//初始化服务配置
obsserviceconfiguration *conf = [[obsserviceconfiguration alloc] initwithurlstring:endpoint credentialprovider:credentialprovider];
// 初始化client
client = [[obsclient alloc] initwithconfiguration:conf];
// 配置所有请求重定向
obswebsiteconfredirectall* redirectall = [obswebsiteconfredirectall new];
redirectall.hostname = @"url";
obssetbucketwebsiterequest *request = [[obssetbucketwebsiterequest alloc]initwithbucketname:@"bucketname" configuration:redirectall];
[client setbucketwebsite:request completionhandler:^(obssetbucketwebsiteresponse *response, nserror *error){
nslog(@"%@",response);
}];
父主题:
相关文档
意见反馈
文档内容是否对您有帮助?
提交成功!非常感谢您的反馈,我们会继续努力做到更好!
您可在查看反馈及问题处理状态。
系统繁忙,请稍后重试
如您有其它疑问,您也可以通过华为云社区问答频道来与我们联系探讨