Amazon S3 REST API 403 error c#

后端 未结 2 1076
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-31 21:00

I\'m trying to get some code working to fetch a file from S3 using the REST API via C#. I\'ve seen other people doing similar things but for some reason I keep getting a 403

相关标签:
2条回答
  • 2020-12-31 21:23

    I tested your code, it works! you just need an extra \n plus change http to https and you're done.

     string stringToConvert = "GET\n"
                              + "\n"
                              + "\n"
                              + "\n"
                              + "x-amz-date:" + timeStamp + "\n"  
                              + "/" + bucketName + "/" + FileName;
    

    Amazon Rest API don't have a good documentation, the lack of examples makes everyone go to the SDK instead.

    0 讨论(0)
  • 2020-12-31 21:24

    I don't know if this is the only problem, but it looks like a definite problem:

    + "x-amz-date:" + httpDate + "\n"
    

    x-amz-date is the header that supercedes the Date: header in the HTTP request itself, but in the string to sign, you just put the date, without "x-amz-date:" or anything in front of it, according to the examples:

    GET\n
    \n
    \n
    Tue, 27 Mar 2007 19:36:42 +0000\n
    /johnsmith/photos/puppy.jpg
    

    http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html#RESTAuthenticationRequestCanonicalization

    There is only one correct signature that can be generated for a request. S3 is going to generate that signature, and compare it to the one you sent, so there's not a single byte of room for error in the string-to-sign.

    0 讨论(0)
提交回复
热议问题