【问题标题】:Azure media service job creation fails using rest api使用 rest api 创建 Azure 媒体服务作业失败
【发布时间】:2017-09-06 10:22:31
【问题描述】:

尝试使用 Azure 媒体服务 rest 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 - "
}
}
}

不知道怎么回事,谢谢

【问题讨论】:

    标签: rest azure asp.net-core azure-media-services


    【解决方案1】:

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

    首先。将 Accept 和 Content-Type 标头都设置为: “应用程序/json;odata=verbose”

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

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

    【讨论】:

    • 内容类型更改为 "application/json; odata=verbose" 有帮助,谢谢
    【解决方案2】:

    问题似乎与“内容类型”有关。由于我使用的是 .net Core,因此将 Conent-type 设置为“application/json; odata=verbose”并不容易。

    1) 尝试使用 RestSharp - dosnt 支持它,它会删除“odata=verbose”部分

    2) 尝试使用 Systsem.Net.Http.HttpClient -> 可能但很难。 将其添加为“接受”:

             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");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-18
      • 2016-05-04
      • 2016-08-26
      • 1970-01-01
      相关资源
      最近更新 更多