Azure encoding job via REST Fails

可紊 提交于 2019-12-12 03:26:31

问题


I am trying to upload a video and encode it via azure rest service. I have now hit the step of encoding the video but I am having difficulties with the request.

The following code shows my request:

 var joburl = res.RequestMessage.RequestUri + "Jobs";
        client = new HttpClient();
        client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "Bearer " + token);
        client.DefaultRequestHeaders.Add("x-ms-version", "2.8");
        client.DefaultRequestHeaders.Add("DataServiceVersion", "3.0");
        client.DefaultRequestHeaders.Add("MaxDataServiceVersion", "3.0");
        client.DefaultRequestHeaders.Add("x-ms-date", date);

        //accept
        t = new NameValueHeaderValue("odata", "verbose");
        type = new MediaTypeWithQualityHeaderValue("application/json");
        type.Parameters.Add(t);
        client.DefaultRequestHeaders.Accept.Add(type);

        result = await client.PostAsync(joburl,json);

the url:https://wamsamsclus001rest-hs.cloudapp.net/api/Jobs

the json:

{"Name":"khgfiuydencodingjob","InputMediaAssets":[{"__metadata":{"Uri":"https://wamsamsclus001rest-hs.cloudapp.net/api/Assets('nb%3acid%3aUUID%3ad037b321-cd1c-43a9-9607-c4910fa7a85b')"}}],"Tasks":[{"Configuration":"H264 Adaptive Bitrate MP4 Set 720p","MediaProcessorId":"nb:mpid:UUID:1b1da727-93ae-4e46-a8a1-268828765609","TaskBody":"<?xml version=\"1.0\"encoding=\"utf-8\"?><taskBody><inputAsset>JobInputAsset(0)</inputAsset><outputAsset>JobOutputAsset(0)</outputAsset></taskBody>"}]}

The bearer token works as I use it for other request.

But I get a bad request 400 with the followin error message:

{"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"}}}

Can anyone spot the error.

Thank you for the help


回答1:


Okay I got it to work. Needed a odata=verbose in my json/string content - like this:

var jobInJson = JsonConvert.SerializeObject(job);
       json = new StringContent(jobInJson, Encoding.UTF8);//, 
       json.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json;odata=verbose");

I tried this earlier however I got a error 500 but now it is working.



来源:https://stackoverflow.com/questions/28451341/azure-encoding-job-via-rest-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!