0

所以我有一些代码已经工作了几个月,但最近它突然停止了。它向 Anilist api 发出请求以获取有关某些动画的信息。

try {
            String query = getQuery();
            query = query.replace("\n", " ").replace("  ", " ");

            URL url = new URL("https://graphql.anilist.co");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setConnectTimeout(5000);
            conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
            conn.addRequestProperty("Accept", "application/json");
            conn.setDoOutput(true);
            conn.setDoInput(true);
            conn.setRequestMethod("POST");

            OutputStream os = conn.getOutputStream();
            os.write(query.getBytes("UTF-8"));
            os.close();

            // read the response
            InputStream in = new BufferedInputStream(conn.getInputStream());
            String result = org.apache.commons.io.IOUtils.toString(in, "UTF-8");

            in.close();
            conn.disconnect();
            //return result
        } catch (Exception exp) {
            System.out.println("exception TRIGGERED");
            System.out.println(exp.getLocalizedMessage());
        }

所以我设置了断点,它似乎在注释“//阅读响应”之后中断。我已经尝试使用Altair GraphQL Client扩展为 google chrome 和https://anilist.co/graphiql上的建议工具尝试相同的请求,它们都可以工作,所以问题似乎与我的代码有关,但我没有t 更新了我的环境。我还有一个在 aws 上运行的代码实例(它是不和谐机器人的一部分),我知道自从我把机器人放在那里后我就没有碰过它。如果您有兴趣,我知道曾经有用的查询之一是

{"query":"query { 
  Media (type: ANIME, search: "naruto") { 
    id
    idMal
    type
    description(asHtml:false)
    chapters
    format
    episodes
    source
    genres
    averageScore 
    popularity
    isAdult
    status
    nextAiringEpisode {
      episode
      airingAt
      timeUntilAiring
    }
    startDate {
      year
      month
      day
    }
    season
    title {
      english
      native
      romaji
    }
    coverImage{
      large
      medium
    }
    studios (isMain: true) {
      nodes {
        id
        name
      }
    }
  }
}"}

任何帮助表示赞赏,非常感谢。

4

0 回答 0