java.io.Exception: Server returned HTTP response code: 403
807603Dec 23 2007 — edited Dec 24 2007hi 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/viewer.fcgi?db=protein&c_start=1&uids=6831583&dopt=fasta&dispmax=1&sendto=t&from=begin&to=end&page=1
at sun.net.www.protocol.http.HttpURLConnection.getInputStream<HttpURLConnection.java.704>
at eutils.main(eutils.java:136)