我在創建POST JOB(用於在OSS中進行翻譯的文件註冊的新名稱)時遇到問題。我已經使用段上傳將ZIP文件上傳到存儲桶(包含2個revit文件,第一個是root,第二個是revitlink),現在我想要觸發轉換爲SVF。爲了這個目的,我使用這段代碼(使用Restharp,Newtonsoft.Json):上述模型衍生API - SVF POST作業始終返回400 - 請求正文不是有效的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到交變量:
{
"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#中創建一個有效的崗位工作?
我改變AddParameter調用AddHeader和結果錯誤保持400 - 巴德請求,只有錯誤消息更改爲:「無法觸發此文件的翻譯。」很難說如果使用可恢復上傳的事實會影響這一點。 – JadaVonRuth
這意味着翻譯不能正常工作... JSON請求沒問題。你是否在使用一個帶有所有.rvt的.zip文件?你能添加更多信息嗎? –
也注意到您的原始代碼使用compressedUrn = true,這意味着它是一個帶有所有.rvt文件的.zip文件。是這樣嗎?如果你只有一個.rvt,只需通過它的甕。 –