0

I would ultimately like to make a HTTP request to the NCBI Entrez database to retrieve some accession numbers. I'm starting out small here, so I wanted to make a functional HTTP request, regardless of the endpoint. But no matter the endpoint I use, a Unknown Host Exception is thrown. Why?

I have included all of my code, but the problem only happens in the method 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);
    }
  }
}
brienna
  • 1,415
  • 1
  • 18
  • 45
  • 1
    Does `host [hostname]` work from the computer where your Java code runs? Are you using a proxy? – Christopher Schultz Jan 12 '17 at 22:47
  • are you sure the link address is correct? – jack jay Jan 12 '17 at 22:48
  • I'm using repl.it to run my code, could that have an effect? – brienna Jan 12 '17 at 22:48
  • It was repl.it that was throwing the error. I guess that site is a form of a proxy? I ran the program from my command line and it worked -- it actually threw a code 403 but that's different matter that was resolved by adding a user agent header. – brienna Jan 14 '17 at 22:43

0 Answers0