【问题标题】:Autodesk-model-derivative: Creating a bucket: The remote server returned an error: (400) Bad RequestAutodesk-model-derivative:创建存储桶:远程服务器返回错误:(400)错误请求
【发布时间】:2016-12-04 03:36:30
【问题描述】:

我正在尝试按照Create an App-Managed Bucket and Upload a File 中的描述创建一个存储桶。当我在命令框中使用 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) 错误请求”。

我以类似的方式获得 OAth 令牌,但不知何故,当我尝试创建存储桶时,它总是返回此异常。

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

【问题讨论】:

    标签: c# autodesk-forge autodesk-model-derivative


    【解决方案1】:

    看起来你在 C# 中测试时指定了大写的存储桶名称。 ""Itx7"" API 帮助说:

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

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

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

    希望这些有用。

    问候,

    梁晓东 锻造崇拜者
    开发者技术服务
    欧特克

    【讨论】:

      猜你喜欢
      • 2018-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-21
      相关资源
      最近更新 更多