Why do I get a 403 error when I try open a URL

前端 未结 1 889
有刺的猬
有刺的猬 2020-12-19 02:55

I am currently using the imdb api from http://imdbapi.org to get some information about a movie. When I use the API and try to open this url in java it gives me a 403 error.

相关标签:
1条回答
  • 2020-12-19 03:22

    You should set User-Agent:

    System.setProperty("http.agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.29 Safari/537.36"); 
    

    or

    URLConnection connection = url.openConnection();
    connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.29 Safari/537.36");
    is = connection.getInputStream();
    
    0 讨论(0)
提交回复
热议问题