Autodesk模型衍生产品:创建存储桶:远程服务器返回错误:(400)错误请求

本文关键字:错误 返回 服务器 请求 模型 存储 创建 Autodesk | 更新日期: 2023-09-27 17:59:09

我正在尝试创建一个bucket,如创建应用程序管理的bucket和上传文件中所述。当我在命令框中使用cURL时,效果很好:

curl
 -v "https://developer.api.autodesk.com/oss/v2/buckets"
 -X "POST"
 -H "Content-Type: application/json"
 -H "Authorization: Bearer ObfuscatedBucketCreateToken"
 -d "{"""bucketKey""":"""itx5""", """policyKey""":"""transient"""}"

现在我试着用C#/visual studio做同样的事情:

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"https://developer.api.autodesk.com/oss/v2/buckets");
    request.Method = "POST";
    UTF8Encoding encoding = new UTF8Encoding();
    Byte[] byteArray = encoding.GetBytes(@"{""bucketKey"":""Itx7"", ""policyKey"":""transient""}");
    request.ContentLength = byteArray.Length;
    request.ContentType = @"application/json";
    request.Headers.Add(@"Authorization: Bearer ObfuscatedBucketCreateToken");
    using (Stream dataStream = request.GetRequestStream())
    {
        dataStream.Write(byteArray, 0, byteArray.Length);
    }
    using (HttpWebResponse webRresponse = (HttpWebResponse)request.GetResponse())
    {
        long length = webRresponse.ContentLength;
        using (Stream stream = webRresponse.GetResponseStream())
        {
            // do your thing
        }
    }

在request.getResponse()上,我得到异常"远程服务器返回错误:(400)Bad request"。

我以类似的方式,我能够获得OAth令牌,但不知何故,当我试图创建一个bucket时,它总是返回这个异常。

为什么会出现此异常?有没有办法调查我为什么会出现这种异常?

Autodesk模型衍生产品:创建存储桶:远程服务器返回错误:(400)错误请求

在C#中测试时,您似乎指定了带大写的bucket名称。"Itx7"API帮助说:

    HTTP / 1.1 **400** Bad Request
     ......
   {
    **"reason":"Valid field 'bucketKey' must be of the form  [-_.a-z0-9]    
    {3,128}"** 
   }

我们有一个关于bucket的博客。大多数描述仍然适用于新版本:

http://adndevblog.typepad.com/cloud_and_mobile/2015/01/buckets-in-autodesk-view-and-data-api.html

希望这些有帮助。

问候,

梁晓东Forge Adovater
开发人员技术服务
Autodesk