首页 > 解决方案 > 必应图像搜索 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);

标签: androidazurerest

解决方案


推荐阅读