0

我最终想向 NCBI Entrez 数据库发出 HTTP 请求,以检索一些入藏号。我从这里开始很小,所以我想发出一个功能性的 HTTP 请求,不管端点是什么。但无论我使用什么端点,都会引发未知主机异常。为什么?

我已经包含了我的所有代码,但问题只发生在方法中getEntireSubject

import java.net.*;
import java.io.*;
import java.util.Scanner;

public class Subject {
  private String id;
  private String sequence;
  // Position on ref sequence where alignment with query begins, inclusive 
  private int start;
  // Position on ref sequence where alignment with query ends, inclusive
  private int end;

  public Subject(String accessNum, int hitFrom, int hitTo, String seq) {
    id = accessNum;
    sequence = seq;
    start = hitFrom;
    end = hitTo;
    getEntireSubject();
  }

  // Getters
  public String getSequence() {
    return sequence;
  }
  public int getStart() {
    return start;
  }
  public int getEnd() {
    return end;
  }

  // Fetches accession number from NCBI
  private void getEntireSubject() {
    try {
      String link = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/einfo.fcgi";
      link = "https://jsonplaceholder.typicode.com/posts/1";
      InputStream response = new URL(link).openStream();

      try (Scanner scanner = new Scanner(response)) {
        String responseBody = scanner.useDelimiter("\\A").next();
       System.out.println(responseBody);
      }
    } catch (Exception e) {
      System.out.println(e);
    }
  }
}
4

0 回答 0