我试图在azure媒体服务中列出我的内容的发布网址列表。 我读到第一步是创建一个Acces Policy。 在MSDN文档中,它表示我将获得带有Id和其他参数的201 Create响应或者301 Moved Permanently响应,因为我需要将请求重新发送到提供的新URL。 我的问题是我得到200 OK响应没有可用的信息:
{
"d": {
"EntitySets": [
"AccessPolicies",
"Locators",
"ContentKeys",
"ContentKeyAuthorizationPolicyOptions",
"ContentKeyAuthorizationPolicies",
"Files",
"Assets",
"AssetDeliveryPolicies",
"AssetFilters",
"IngestManifestFiles",
"IngestManifestAssets",
"IngestManifests",
"StorageAccounts",
"Tasks",
"NotificationEndPoints",
"Jobs",
"TaskTemplates",
"JobTemplates",
"MediaProcessors",
"EncodingReservedUnitTypes",
"Operations",
"StreamingEndpoints",
"Channels",
"Programs",
"Filters"
]
}
}
我的代码:
public void Create()
{
if (string.IsNullOrWhiteSpace(Name))
{
Name = Guid.NewGuid().ToString();
}
string accessPolicyCreateRequestPayloadFormat = @"{0} ""Name"": ""{1}"", ""DurationInMinutes"": ""{2}"", ""Permissions"":""{3}"" {4}";
string requestBody = string.Format(CultureInfo.InvariantCulture, accessPolicyCreateRequestPayloadFormat, "{", Name, DurationInMinutes.TotalMinutes, (int)Permissions, "}");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(string.Format(CultureInfo.InvariantCulture, "{0}AccessPolicies", _context.WamsEndpoint));
request.Method = HttpVerbs.Post;
request.ContentType = RequestContentType.Json;
request.Accept = RequestContentType.Json;
request.Headers.Add(RequestHeaders.XMsVersion, RequestHeaderValues.XMsVersion);
request.Headers.Add(RequestHeaders.Authorization, string.Format(CultureInfo.InvariantCulture, RequestHeaderValues.Authorization, _context.AccessToken));
request.Headers.Add(RequestHeaders.DataServiceVersion, RequestHeaderValues.DataServiceVersion);
request.Headers.Add(RequestHeaders.MaxDataServiceVersion, RequestHeaderValues.MaxDataServiceVersion);
request.ContentLength = Encoding.UTF8.GetByteCount(requestBody);
using (StreamWriter streamWriter = new StreamWriter(request.GetRequestStream()))
{
streamWriter.Write(requestBody);
}
using (var response = (HttpWebResponse)request.GetResponse())
{
switch (response.StatusCode)
{
case HttpStatusCode.MovedPermanently:
_context.CheckForRedirection();
Create();
break;
case HttpStatusCode.Created:
using (Stream responseStream = response.GetResponseStream())
{
using (StreamReader streamReader = new StreamReader(response.GetResponseStream(), true))
{
var returnBody = streamReader.ReadToEnd();
JObject responseJsonObject = JObject.Parse(returnBody);
var d = responseJsonObject["d"];
Id = d.Value<string>("Id");
DurationInMinutes = TimeSpan.FromMinutes(d.Value<double>("DurationInMinutes"));
Permissions = (AccessPolicyPermission)d.Value<int>("Permissions");
Name = d.Value<string>("Name");
Created = d.Value<DateTime>("Created");
LastModified = d.Value<DateTime>("LastModified");
}
}
break;
default:
Console.WriteLine(response.StatusDescription);
break;
}
}
}