android - 必应图像搜索 API 失败
问题描述
我尝试通过 bing 图像搜索 api 下载图像。打开与端点的连接后出现错误:
java.io.FileNotFoundException: https://api.cognitive.microsoft.com/bing/v7.0/images/search?q=Der+Rueckkehrer+Bluray
这是我的代码:
String subscriptionKey = "my sub key";
String host = "https://api.cognitive.microsoft.com";
String path = "/bing/v7.0/images/search";
URL url = new URL(host + path + "?q=" + URLEncoder.encode(productName, "UTF-8"));
HttpsURLConnection connection = (HttpsURLConnection)url.openConnection();
connection.setRequestProperty("Ocp-Apim-Subscription-Key", subscriptionKey);
System.out.println("URL " + url);
// receive JSON body
InputStream stream = connection.getInputStream(); <--- Crash
bingResult = readStream(stream);
解决方案
推荐阅读
- javascript - 浏览单个页面的上一个和下一个按钮
- python-3.x - Python Requests 模块 - 它是否使用系统级别(在 Windows 上)代理设置?
- html - CSS 定位问题(拆分按钮下拉菜单) - 无法将元素移动到另一侧并坐在按钮旁边
- flutter - 为什么 SmartRefresher 无法正常工作
- flutter - 动态更改小部件的文本颤动/飞镖
- swift - SwiftUI ScrollView 不跟随链式动画
- android - 如何在超过 10 次以上的片段中管理 BackPress?
- r - 问题:根据 data.table 中其他元素的数量随机选择行?
- python - 编写一个函数,返回数据集中列中唯一名称的数量 - Python
- mysql - MYSQLDUMP:@符号后更改内容