1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| BufferedReader reader = null;
String text = new String();
try {
URL url2 = new URL(url.getUrlString().replace(" ", "%20")); //.replace("|", "%7C").replace("{", "%7B").replace("{", "%7D")
URLConnection conn = url2.openConnection();
conn.setRequestProperty( "Host", url2.getHost() );
conn.setConnectTimeout(60 * 1000);
conn.setRequestProperty( "Accept", "text/javascript, text/html, application/xml, text/xml, */*" );//text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
conn.setRequestProperty( "Accept-Language", "fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3" );
conn.setRequestProperty( "Connection", "keep-alive" );
conn.setRequestProperty( "X-Requested-With", "XMLHttpRequest" );
conn.setRequestProperty( "X-Prototype-Version", "1.7" );
conn.setRequestProperty( "User-Agent", this.userAgent );
if(Fc.cookieValue!=null) conn.setRequestProperty("Cookie", Fc.cookieValue);
if(Fc.CSRFToken!=null) conn.setRequestProperty("X-CSRFToken",Fc.CSRFToken);
//conn.setDoOutput(true); //mode POST
//lecture de la réponse
reader = new BufferedReader(new InputStreamReader(conn.getInputStream() )); //ARRET ICI
StringBuilder sb = new StringBuilder();
char[] cbuf = new char[8192];
int len;
while ( (len = reader.read(cbuf)) >= 0 ) { //ARRET ICI
sb.append(cbuf, 0, len);
}
text = sb.toString();
}catch (Exception e) {
System.out.println("Echec du chargement de "+url.getUrlString()+" "+e.toString());
}finally{
try{ if(reader!=null) reader.close(); }catch(Exception e){
Applet_VeilleConcurentielle.erreur(e);
}
} |
Partager