I am trying to make a http get request using java ,when i am executing the code ,i am getting 403 forbidden
code .Is there any way to get rid of that ?my code is
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.*;
public class Http {
private final String USER_AGENT = "Mozilla/5.0";
public static void main(String [] args){
Http http=new Http();
try {
http.get();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void get() throws Exception{
URL ob=new URL("http://www.google.com/search?q=vamsi");
HttpURLConnection con=(HttpURLConnection) ob.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("USER_AGENT", USER_AGENT);
int responseCode=con.getResponseCode();
System.out.println("Response code is "+responseCode);
BufferedReader buf=new BufferedReader(new InputStreamReader(con.getInputStream()));
String input;
StringBuffer response =new StringBuffer();
while((input=buf.readLine())!=null){
response.append(input);
}
buf.close();
System.out.println(response.toString());
}
}