知道如何将 OAuth 标头注入 PlayReadyLicenseAcquisitionServiceRequest 以便它们包含在 BeginServiceRequest() 中吗?我无法利用许可证 URL 的查询字符串,或在正文中嵌入 OAuth 令牌;它必须在许可证检索的 http 请求的标头中。
1 回答
0
我在这里找到了一些很棒的示例代码:
https://www.eyecatch.no/blog/using-playready-and-smooth-streaming-in-a-windows-10-uwp-app/
但这是下面的魔法酱(加上我的标题):
public static async Task<bool> RequestLicenseManual(PlayReadyLicenseAcquisitionServiceRequest request, params KeyValuePair<string, object>[] headers)
{
Debug.WriteLine("ProtectionManager PlayReady Manual License Request in progress");
try
{
var r = request.GenerateManualEnablingChallenge();
var content = new ByteArrayContent(r.GetMessageBody());
foreach (var header in r.MessageHeaders.Where(x => x.Value != null))
{
if (header.Key.Equals("Content-Type", StringComparison.OrdinalIgnoreCase))
{
content.Headers.ContentType = MediaTypeHeaderValue.Parse(header.Value.ToString());
}
else
{
content.Headers.Add(header.Key, header.Value.ToString());
}
}
var msg = new HttpRequestMessage(HttpMethod.Post, r.Uri) { Content = content };
foreach (var header in headers)
{
msg.Headers.Add(header.Key, header.Value.ToString());
}
Debug.WriteLine("Requesting license from {0} with custom data {1}", msg.RequestUri, await msg.Content.ReadAsStringAsync());
var client = new HttpClient();
var response = await client.SendAsync(msg);
if (response.IsSuccessStatusCode)
{
request.ProcessManualEnablingResponse(await response.Content.ReadAsByteArrayAsync());
}
else
{
Debug.WriteLine("ProtectionManager PlayReady License Request failed: " + await response.Content.ReadAsStringAsync());
return false;
}
}
catch (Exception ex)
{
Debug.WriteLine("ProtectionManager PlayReady License Request failed: " + ex.Message);
return false;
}
Debug.WriteLine("ProtectionManager PlayReady License Request successfull");
return true;
}
于 2016-12-19T14:40:34.450 回答