我花了好几天的时间试图弄清楚这一点,看看我可以在Azure网站,Azure git集线器以及所有相关的堆栈溢出帖子中找到的所有信息。我希望我缺少一些简单的东西。Azure Billing API返回403
我使用的示例Java代码被发布在网络上得到的令牌:
try {
exec = Executors.newFixedThreadPool(1);
context = new AuthenticationContext("https://login.microsoftonline.com/8e4f0713-5eea-4da0-99c0-xxxxxxxxxxxx",
true, exec);
ClientCredential cred = new ClientCredential(webClientID, clientSecret);
Future<AuthenticationResult> future = context.acquireToken("https://management.azure.com/", cred, null);
result = future.get();
} catch(Exception e) {
logger.warn("Exception " + e);
} finally {
exec.shutdown();
}
if (result == null) {
return null;
}
return result.getAccessToken();
这产生一个令牌,其余放入请求头:
Authorization: Bearer -token-
The GET https://management.azure.com/subscriptions/758ad253-cbf5-4b18-8863-xxxxxxxxxxxx/providers/Microsoft.Commerce/RateCard?api-version=2015-06-01-preview%26%24filter%3DOfferDurableId+eq+%27MS-AZR-0003p%27+and+Currency+eq+%27USD%27+and+Locale+eq+%27en-US%27+and+RegionInfo+eq+%27US%27
返回403码:
Exception: java.io.IOException: Server returned HTTP response code: 403 for URL: https://management.azure.com/subscriptions/758ad253-cbf5-4b18-8863-xxxxxxxxxxxx/providers/Microsoft.Commerce/RateCard?api-version=2015-06-01-preview%26%24filter%3DOfferDurableId+eq+%27MS-AZR-0003p%27+and+Currency+eq+%27USD%27+and+Locale+eq+%27en-US%27+and+RegionInfo+eq+%27US%27
接头: [0]空:HTTP/1.1 403禁止
[1]的Cache-Control:无缓存
[2]的Pragma:无缓存
[3]内容类型:应用/ JSON;字符集= UTF-8
[4]过期:-1
[5] X-MS-失败原因:网关
[6] X-MS-请求-ID:e4ad9253-E034 -481d-aba0-f46902b7057f
[7] X-MS-相关请求-ID:e4ad9253-e034-481d-aba0-f46902b7057f
[8] X-MS-路由请求-ID:EASTUS :20151103T205103Z:e4ad9253-e034-481d-aba0-f46902b7057f
[9]严格交通安全:最大年龄= 31536000; includeSubDomains
[10]日期:星期二,2015年11月3日20时51分02秒GMT
[11]连接:关闭
[12]的Content-Length:303
我所做的一切在Azure MGMT控制台上的设置,以创建应用程序在Azure的AD,得到clientID的&客户端密钥等。SSL/HTTPS代码:
azureURL = new java.net.URL(url);
con = (HttpsURLConnection)azureURL.openConnection();
con.disconnect();
con.setDoOutput(true);
con.setDoInput(true);
con.setUseCaches(false);
con.setSSLSocketFactory(MyUtils.getSSLSocketFactory());
con.setRequestMethod("GET");
con.setRequestProperty("x-ms-version", "2015-06-01-preview");
con.setRequestProperty("Content-Type", "application/json");
String token = getAccessTokenFromServicePrincipalCredentials();
if (token != null) {
con.setRequestProperty("Authorization", "Bearer " + token);
con.connect();
in = (InputStream)con.getContent();
InputStreamReader inr = new InputStreamReader(in);
} else {
logger.warn("unable to obtain prices");
}
任何建议关于如何调试问题?
谢谢,我添加了应用程序本身作为贡献者,403消失了。现在我得到一个404文件未找到。 –
您应该在错误中获得更多详细信息。你介意分享这些细节吗? –
这是一个例外:java.io.FileNotFoundException:https://management.azure.com/subscriptions/758ad253-cbf5-4b18-8863-3eed0825bf07/providers/Microsoft.Commerce/RateCard?api-version=2015-06- 01预览%26%24filter%3DOfferDurableId + EQ +%27MS-AZR-0003p%27 +和+货币+ EQ +%27USD%,27 +和+地点+ EQ +%27en美%27 +和+ RegionInfo + EQ +%27US% 27 –