Setting Azure Encoding with REST Fails

I am trying to upload a video and encode it through the azure rest service. Now I have taken the step of encoding the video, but I'm having difficulty with the request.

The following code shows my query:

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

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

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 carrier token works as I use it for another request.

But I get a bad 400 request with an 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 detect a bug.

thanks for the help

0
source share
1 answer

Ok, I earned it. I need to add 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");

, 500, .

+2

Source: https://habr.com/ru/post/1679110/


All Articles