Autodesk-model-derivative:创建存储桶:远程服务器返回错误:(400)错误请求

时间:2016-07-29 12:08:18

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

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

为什么我会收到此异常?有没有办法调查为什么我得到这个例外?

1 个答案:

答案 0 :(得分:2)

在C#中进行测试时,您看起来用大写字母指定了存储桶名称。     “” Itx7 “” API帮助说:

ajaxCall {
    # your code
    config.sys_language_uid = 0
}

# condition for the language. Adjust it to your language id
[globalVar = GP:L = 1]
ajaxCall.config.sys_language_uid = 1
[global]

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

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

希望这些有用。

此致

梁晓东   伪造Adovater
  开发者技术服务
  的Autodesk