开发者社区> 问答> 正文

求助IOS版本的OSSSDK使用问题

我想使用IOS版本的SDK 访问BUCKUT下的object时,报错如下:

Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found." UserInfo=0x7f90d9744200 {NSUnderlyingError=0x7f90d967caa0 "A server with the specified hostname could not be found.", NSErrorFailingURLStringKey=http://mysharecdv.oss-cn-beijing-a.aliyuncs.com/21AA7BD3-6797-4C15-9CB8-D1DB1751567C.jpg, NSErrorFailingURLKey=http://mysharecdv.oss-cn-beijing-a.aliyuncs.com/21AA7BD3-6797-4C15-9CB8-D1DB1751567C.jpg, _kCFStreamErrorDomainKey=12, _kCFStreamErrorCodeKey=8, NSLocalizedDescription=A server with the specified hostname could not be found.}


相关代码如下:
OSSClient *ossclient = [ OSSClient sharedInstanceManage ];
    [ossclient setGlobalDefaultBucketHostId :@"oss-cn-beijing-a.aliyuncs.com" ];
    [ossclient setGlobalDefaultBucketAcl :PUBLIC_READ_WRITE ] ;
     NSString *accessKey = @"---------";
     NSString *secretKey = @"-------" ;
    [ossclient setGenerateToken:^( NSString *method, NSString *md5, NSString *type, NSString *date, NSString *xoss, NSString *resource){
         NSString *signature = nil;
         NSString *content = [ NSString stringWithFormat: @"%@\n%@\n%@\n%@\n%@%@", method, md5, type, date, xoss, resource];
        signature = [ OSSTool calBase64Sha1WithData:content withKey:secretKey];
        signature = [ NSString stringWithFormat: @"OSS %@:%@", accessKey, signature];
         NSLog( @"here signature:%@", signature);
         return signature;
    }];
     OSSBucket *bucket = [[ OSSBucket alloc] initWithBucket: @"mysharecdv"];
    [bucket setOssHostId :@"oss-cn-beijing-a.aliyuncs.com" ] ;
    [bucket setAcl :PUBLIC_READ_WRITE ] ;
    
     testData = [[ OSSData alloc ] initWithBucket :bucket withKey :@"21AA7BD3-6797-4C15-9CB8-D1DB1751567C.jpg" ];
     NSError * objerror = nil;

     NSData * data = [ testData get:&objerror];


   objerror 返回上面的错误
   跪求解答啊


RESTful 错误:
?xml version="1.0" encoding="UTF-8"?>
<Error>
  <Code>SignatureDoesNotMatch</Code>
  <Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>
  <StringToSignBytes>50 4F 53 54 0A 0A 74 65 78 74 2F 70 6C 61 69 6E 3B 20 63 68 61 72 73 65 74 3D 75 74 66 2D 38 0A 54 75 65 2C 20 30 36 20 4A 61 6E 20 32 30 31 35 20 31 31 3A 30 39 3A 31 32 20 47 4D 54 0A 2F 63 64 76 74 65 73 74 31 2F 30 66 64 30 32 38 36 30 2D 37 32 65 62 2D 34 32 33 66 2D 61 30 63 63 2D 30 30 34 61 34 33 35 35 66 65 31 35 5F 74 68 75 6D 62 5F 37 33 33 36 39 32 34 33 2D 35 41 36 32 2D 34 45 36 36 2D 39 30 30 31 2D 44 34 34 32 43 39 34 46 30 43 39 35 2E 4A 50 47 3F 75 70 6C 6F 61 64 73 </StringToSignBytes>
  <SignatureProvided>7YcjvbaQO4ZvMp4woMatKY5ig9c=</SignatureProvided>
  <StringToSign>POST

text/plain; charset=utf-8
Tue, 06 Jan 2015 11:09:12 GMT
/cdvtest1/0fd02860-72eb-423f-a0cc-004a4355fe15_thumb_73369243-5A62-4E66-9001-D442C94F0C95.JPG?uploads</StringToSign>
  <OSSAccessKeyId>wm4Cl6Z3DohBpumS</OSSAccessKeyId>
  <RequestId>54ABC25DCA2A04852A97AF79</RequestId>
  <HostId>cdvtest1.oss-cn-beijing.aliyuncs.com</HostId>
</Error>
另外我们在开发时,使用RESTful接口,[size=; font-size: 12pt,12pt][font='Times New Roman'] 加签在业务数据库完成,在安卓版本使用时,Authorization 的值必须Trim下才能使用,在IOS下没有Trim函数,SignatureProvided数据与我生成的完全一样始终返回上诉错误,跪求方案,OSSTool 中的+ ( NSString *)trimString:( NSString *)string withCharactersInString:( NSString *)characters能解决问题吗,怎么用?



展开
收起
王新顺 2015-01-06 14:55:26 16054 0
1 条回答
写回答
取消 提交回答
  • Re求助IOS版本的OSSSDK使用问题
    你这个oss-cn-beijing-a.aliyuncs.com是不是写错了,把应该是oss-cn-beijing.aliyuncs.com才对吧。
    2015-01-07 09:30:35
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
OSS运维进阶实战手册 立即下载
《OSS运维基础实战手册》 立即下载
OSS运维基础实战手册 立即下载