Query the website and get result

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eternalLearner
    New Member
    • May 2007
    • 35

    Query the website and get result

    i need to send the query to the website and get the result.
    but for the following code, it returns
    java.net.Connec tException: Connection refused
    import java.io.Buffere dReader;
    import java.io.InputSt ream;
    import java.io.InputSt reamReader;
    import java.net.URL;

    public class Sample1 {

    public static void main(String[] args) {

    try {
    String url = "http://www.xyz.cn/RNA";
    String Query = "/>Example \nCUUGGGAAUGGCA AGGAAACCGUUACCA UUACUGAGUUUAGUA AUGGUAAUGGUUCUC UUGCUAUACCCAGA" ;


    String request = url;
    request = request + "?";
    request = request + Query;

    URL serviceURL = new URL(request);
    InputStream is = serviceURL.open Stream();
    //InputStreamRead er isr = new InputStreamRead er(is,"UTF-8");
    InputStreamRead er isr = new InputStreamRead er(is);
    BufferedReader br = new BufferedReader( isr);

    StringBuffer response = new StringBuffer();
    String nextLineFromSer vice = br.readLine();
    while (nextLineFromSe rvice != null) {
    response.append (nextLineFromSe rvice);
    nextLineFromSer vice = br.readLine();
    }

    System.out.prin tln(response);
    }
    catch (Exception e) {
    System.out.prin tln(e);
    }

    }
    }
    help required as i cant understand how to proceed further.
    Thanks in advance
    Last edited by eternalLearner; Dec 27 '08, 08:05 AM. Reason: query not properly formatted
  • eternalLearner
    New Member
    • May 2007
    • 35

    #2
    hi
    can anybody tell me please......
    :)

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by eternalLearner
      i need to send the query to the website and get the result.
      but for the following code, it returns
      java.net.Connec tException: Connection refused


      help required as i cant understand how to proceed further.
      Thanks in advance
      That exception is thrown when there is no such service available at that particular URL. Can you connect to it by using a browser? btw, what is that newline character doing in your query String?

      kind regards,

      Jos

      Comment

      Working...