2016-05-02 166 views
2

我试图访问该文档现在https://azure.microsoft.com/en-us/documentation/articles/media-services-rest-connect-programmatically/C#中使用REST API

我的代码看起来是这样的令牌下面连接到Azure的媒体服务帐户:

string requestUrl = String.Format("https://MyAccessControlNamespace.accesscontrol.windows.net/v2/OAuth2-13"); 
string bodyURL = string.Format("grant_type=client_credentials&client_id=MyMediaServicesAccountName&client_secret=MyAccountKeyEncodedToUrl&scope=urn%3aWindowsAzureMediaServices"); 

var request = (HttpWebRequest)WebRequest.Create(requestUrl); 
request.Method = "POST"; 
request.ContentType = "application/x-www-form-urlencoded"; 
request.Accept = "application/json"; 

byte[] requestBodyBytes = new ASCIIEncoding().GetBytes(bodyURL); 
Stream requestStream = await request.GetRequestStreamAsync(); 
requestStream.Write(requestBodyBytes, 0, requestBodyBytes.Length); 

var response = (HttpWebResponse) await request.GetResponseAsync(); 

我也使用HttpClient的尝试。但我总是得到400错误请求错误...

我会非常感谢任何帮助/提示!

+1

你能抓住提琴手的要求吗?它看起来像是由于某种原因格式不正确 –

+1

可能有帮助 - Azure媒体服务错误代码https://msdn.microsoft.com/en-us/library/azure/dn168949.aspx – Set

+0

非常感谢您的提示!提琴手显示“错误:invalid_client”,所以我想我没有在Active Directory或正确的设置。 无论如何,我决定使用Media Services .NET SDK创建Web API应用程序,因为我被这个问题困住了。 – Spot

回答

0

媒体服务访问控制地址是https://wamsprodglobal001acs.accesscontrol.windows.net/。它不是AD的访问控制名称空间。

更改为:
string requestUrl = String.Format("https://wamsprodglobal001acs.accesscontrol.windows.net/v2/OAuth2-13");

确保您的媒体账号密码进行编码。