2016-07-29 117 views
1

我试图按照Create an App-Managed Bucket and Upload a File中所述创建存储桶。当我在命令框中使用卷曲,它的工作原理好:Autodesk-model-derivative:创建存储桶:远程服务器返回错误:(400)错误的请求

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#做同样的/视觉工作室:

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令牌,但不知何故,当我尝试创建一个存储桶时,它总是返回此异常。

为什么我会得到这个异常?有没有办法来调查为什么我得到这个异常?

回答

2

看起来你在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

希望这些是有帮助的。

问候,

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

+0

是的,这确实的伎俩!谢谢。 –

相关问题