Can't read in HTML content from valid URL

I am trying out a simple program for reading the HTML content from a given URL. The URL I am trying in this case doesn't require any cookie/username/password, but still I am getting a **io.IOException: Server returned HTTP response code: 403** error. Can anyone tell me what am I doing wrong here? (I know there are similar question in SO, but they didn't help): import java.net.*; import java.io.*; import java.net.MalformedURLException; import java.io.IOException; public class urlcont { public static void main(String[] args) { try { URL u = new URL("http://www.amnesty.org/"); URLConnection uc = u.openConnection(); uc.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); uc.connect(); InputStream in = uc.getInputStream(); int b; File f = new File("C:\\Users\\kausta\\Desktop\\urlcont.txt"); f.createNewFile(); OutputStream s = new FileOutputStream(f); while ((b = in.read()) != -1) { s.write(b); } } catch (MalformedURLException e) {System.err.println(e);} catch (IOException e) {System.err.println(e);} } }

以上就是Can't read in HTML content from valid URL的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏