我正在尝试按照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 令牌,但不知何故,当我尝试创建存储桶时,它总是返回此异常。
为什么我会得到这个异常?有没有办法调查我为什么会得到这个异常?