【发布时间】:2016-12-17 03:04:47
【问题描述】:
我正在尝试从 android 调用 ms 认知服务。但是,获取访问令牌的 api 不起作用.. 下面是 android 代码
HttpPost httpPost = new HttpPost("https://api.cognitive.microsoft.com/sts/v1.0/issueToken");
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(2);
nameValuePair.add(new BasicNameValuePair("Ocp-Apim-Subscription-Key", "my subscription key"));
try {
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
} catch (UnsupportedEncodingException e) {
}
try {
HttpResponse response = httpClient.execute(httpPost);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
在 logcat 中,我得到错误:
java.net.UnknownHostException: Unable to resolve host "api.cognitive.microsoft.com": No address associated with hostname
api url“https://api.cognitive.microsoft.com/sts/v1.0/issueToken”有变化吗?
另外,当我在浏览器中输入此 URL“https://api.cognitive.microsoft.com/sts/v1.0/issueToken”时,我会收到消息
{ "statusCode": 404, "message": "Resource not found" }
请帮忙。
【问题讨论】:
-
关于“无法解析主机“api.cognitive.microsoft.com””的应用程序端 - 检查防火墙/dns。在浏览器中的行为是正确的,只要 GET 什么都不做 - 你应该在那里发布以获取令牌。
-
我确认没有任何东西阻止请求.. 防火墙/dns 上没有任何东西。感谢您的建议。还有什么想法。
-
所以这毕竟是一个错字?
标签: android azure authentication http-post microsoft-cognitive