2016-07-29 120 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

是的,這確實的伎倆!謝謝。 –

相關問題