我在创建 POST JOB(用于在 OSS 中注册文件以进行翻译的新名称)时遇到问题。我已经使用分段上传将 ZIP 文件上传到存储桶(包含 2 个 revit 文件,第一个是 root,第二个是 revitlink),有它的 URN,现在我想触发转换为 SVF。为此,我正在使用这段代码(使用 Restharp,Newtonsoft.Json):
public void CreatePostJOB(string serviceUrl, string urn, string rootFile, string token)
{
try
{
RestClient client = new RestClient(serviceUrl);
RestRequest request = new RestRequest();
request.Method = Method.POST;
request.Resource = "modelderivative/v2/designdata/job";
request.RequestFormat = DataFormat.Json;
request.AddParameter("Authorization", "Bearer " + token, ParameterType.HttpHeader);
request.AddParameter("x-ads-force", true);
request.AddParameter("Content-Type", "application/json");
JObject jsonbody = new JObject
(
new JProperty("input", new JObject
(
new JProperty("urn", urn),
new JProperty("compressedUrn", true),
new JProperty("rootFileName", rootFile)
)),
new JProperty("output", new JObject
(
new JProperty("formats", new JArray
(
new JObject
(
new JProperty("type", "svf"),
new JProperty("views", new JArray("3d", "2d"))
)
))
))
);
string post = jsonbody.ToString(Formatting.Indented);
request.AddParameter("application/json", post, ParameterType.RequestBody);
IRestResponse resp = client.Execute(request);
if (resp.StatusCode == HttpStatusCode.OK)
{
//TODO
}
}
catch (Exception ex)
{
//TODO
}
}
上面的代码会将以下 JSON 生成到 post 变量中:
{
"input": {
"urn": "/*urn base64 string with no padding*/",
"compressedUrn": true,
"rootFileName": "MainModel_A.rvt"
},
"output": {
"formats": [
{
"type": "svf",
"views": [
"3d",
"2d"
]
}
]
}
无论我如何更改此代码结果总是相同的:
{"diagnostic":"Request body is not a valid json"}
我还尝试使用具有相同结果的普通 C# WebRequest。也许有一个错误,因为来自同一 API 的其他调用与 restsharp 一起工作就像一个魅力。请问如何在 C# 中创建有效的发布作业?