使用 rest api 创建 Azure 媒体服务作业失败

Azure media service job creation fails using rest api

正在尝试使用 Azure 媒体服务休息 api。 (按照教程:https://docs.microsoft.com/en-us/azure/media-services/media-services-rest-get-started

在我尝试创建作业之前一切正常。发送与示例中相同的请求(资产 ID 和令牌除外)并获得响应: 解析请求内容失败,原因是:确保仅使用由类型

定义的 属性 名称

要求:

    POST https://wamsdubclus001rest-hs.cloudapp.net/api/Jobs HTTP/1.1
    Connection: Keep-Alive
    Content-Type: application/json
    Accept: application/json; odata=verbose
    Accept-Charset: UTF-8
    Authorization: Bearer token -> here i send real token
    DataServiceVersion: 1.0;NetFx
    MaxDataServiceVersion: 3.0;NetFx
    x-ms-version: 2.11
    Content-Length: 458
    Host: wamsdubclus001rest-hs.cloudapp.net

        {
        "Name":"TestJob",
        "InputMediaAssets":[
        {
        "__metadata":{
        "uri":"https://wamsdubclus001rest-hs.cloudapp.net/api/Assets('nb%3Acid%3AUUID%3A5168b52a-68ed-4df1-bac8-0648ce734ff6')"
        }
        }
        ],
        "Tasks":[
        {
        "Configuration":"Adaptive Streaming",
        "MediaProcessorId":"nb:mpid:UUID:ff4df607-d419-42f0-bc17-a481b1331e56",
        "TaskBody":"<?xml version=\"1.0\" encoding=\"utf-8\"?><taskBody><inputAsset>JobInputAsset(0)</inputAsset> <outputAsset>JobOutputAsset(0)</outputAsset></taskBody>"
        }
        ]
        }

回复:

{
"error":{
"code":"",
"message":{
"lang":"en-US",
"value":"Parsing request content failed due to: Make sure to only use property names that are defined by the type"
}
}
}

好像和__metadata属性有关。当我按照此处的说明进行操作时:Creating Job from REST API returns a request property name error,错误更改:

"error":{
"code":"",
"message":{
"lang":"en-US",
"value":"Invalid input asset reference in TaskBody - "
}
}
}

不知道哪里出了问题,谢谢

让我检查一下,但这可能是我过去 运行 遇到的几个问题。

首先。将 Accept 和 Content-Type headers 设置为: "application/json; odata=verbose"

接下来,仔细检查您是否确实在元数据中使用了长下划线字符 属性。我遇到过发送错误的下划线字符并且与 属性 名称不匹配的问题。

如果其中任何一个有帮助,请告诉我。

问题似乎与 "Content-Type" 有关。由于我使用的是 .net Core,因此将内容类型设置为 "application/json; odata=verbose".

并不容易

1) 尝试使用 RestSharp - 不支持它,它削减了 "odata=verbose" 部分

2) 尝试 Systsem.Net.Http.HttpClient -> 可能但困难。 将其添加为 "Accept" :

         MediaTypeWithQualityHeaderValue mtqhv;

         MediaTypeWithQualityHeaderValue.TryParse("application/json;odata=verbose", out mtqhv);

         client.DefaultRequestHeaders.Accept.Add(mtqhv);//ACCEPT header

将其添加为 "Content-Type" :

request.Content = new StringContent(content,
System.Text.Encoding.UTF8); //CONTENT-TYPE header -> default type will be text/html

request.Content.Headers.Clear();  // need to clear it - it will fail otherwise
request.Content.Headers.TryAddWithoutValidation("Content-Type","application/json;odata=verbose");