java.io.Exception: Server returned HTTP response code: 403


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: java.io.Exception: Server returned HTTP response code: 403

  1. #1
    Join Date
    Dec 2007
    Posts
    9

    java.io.Exception: Server returned HTTP response code: 403

    hi can anyone tell me what might be the error in the following code(this is only the part of my code where the error is occuring )

    Properties systemSettings = System.getProperties();
    systemSettings.put("http.proxyHost","132.147.160.1");
    systemSettings.put("http.proxyPort", "8084");
    String record = null;
    FileReadTest f = new FileReadTest();

    /*opening the text document*/
    try{
    File fi = new File("gi2.txt");
    FileInputStream fis = new FileInputStream(fi);
    BufferedInputStream bis = new BufferedInputStream(fis);
    DataInputStream dis = new DataInputStream(bis);

    while ( (record=dis.readLine()) != null )
    {
    /*url connection*/

    URL url=new URL("http://www.ncbi.nlm.nih.gov/entrez/viewer.fcgi?db=protein&c_start=1&uids="record"&dopt=fasta&dispmax=1&sendto=t&from=begin&to =end&page=1");
    HttpURLConnection urlConn = (HttpURLConnection)url.openConnection();
    urlConn.setRequestProperty("User-agent","Mozilla/2.0.0.11");
    urlConn.connect();

    /*creating a text file*/
    File create = new File(record+".txt");
    try
    {
    if(!create.exists())
    {
    create.createNewFile();
    }
    else
    {
    System.out.println("file already exists");
    }
    }
    catch(IOException e)
    {
    System.err.println("cannot create a file");
    }


    it was returning me the following error
    java.io.Exception: Server returned HTTP response code: 403 for URL: http://www.ncbi.nlm.nih.gov/entrez/v...&to=end&page=1
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream<HttpURLConnection.java.704>
    at eutils.main(eutils.java:136)

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Does it tell you what line the error is happening on?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Dec 2007
    Posts
    9
    String inputline;
    StringBuffer tmp = new StringBuffer();
    BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
    while ((inputline=in.readLine()) != null)
    {
    tmp.append(inputline+"\n");
    }
    /*opening a created file and writing to it*/
    BufferedWriter out = new BufferedWriter(new FileWriter(record+".txt", true));
    out.write(tmp+"\n");
    out.close();

    }
    }
    catch ( MalformedURLException ex)
    {
    ex.printStackTrace();}
    }
    catch ( IOException ex) {
    ex.printStackTrace();
    }


    in the above code it was showing an error in the line 3 where it has to retrieve the information using the urlconnection...

Similar Threads

  1. Replies: 4
    Last Post: 09-26-2007, 12:49 PM
  2. VS.Net and Code Behind
    By Chaitanya Marvici in forum ASP.NET
    Replies: 6
    Last Post: 07-21-2003, 10:15 AM
  3. Remove exchange from a site
    By andriano in forum Enterprise
    Replies: 1
    Last Post: 10-02-2000, 04:54 PM
  4. Replies: 7
    Last Post: 09-15-2000, 09:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center