나는이 사용하는 자바에 http://www.meuhumor.com.br/을 읽으려고 해요 :왜 자바에서 웹 사이트 URL을 읽는 중 403 오류가 발생합니까?
URL url;
HttpURLConnection connection = null;
try{
url = new URL(targetURL);
connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("Content-Language", "en-US");
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11");
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
DataOutputStream dataout = new DataOutputStream(connection.getOutputStream());
dataout.flush();
dataout.close();
InputStream is = connection.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line;
StringBuffer response = new StringBuffer();
while((line = br.readLine()) != null){
response.append(line);
response.append('\n');
}
br.close();
String html = response.toString();
내가 어떤 브라우저를 사용하여 웹 사이트에 액세스 할 수 있습니다,하지만 난 자바 메신저 점점 때 java.io.IOException와 HTML을 얻을하려고하면 서버가 반환 HTTP 응답 코드 : URL에 대해 403 :
누군가가 HTML을 가져 오는 방법을 알고 있습니까?
왜 서버에 POST합니까? – nhahtdh
전에 GET 해보고 같은 오류가 발생했습니다 ... 나는이 코드를 다른 웹 사이트에서 사용할 수 있도록이 코드를 사용하여 읽는 것을 읽었지 만이 웹 사이트에서는 작동하지 않습니다 ... – Igor