- 06.11.2007
- 3 328
- 42
Есть стандартная связка LS+Java, которая по http вытягивает json
теперь её нужно переделать, чтобы по httpS можно было получать тот же json
при этом имеется cert.pem для авторизации
подскажите как это переделать в яве не силён
теперь её нужно переделать, чтобы по httpS можно было получать тот же json
при этом имеется cert.pem для авторизации
подскажите как это переделать в яве не силён
Код:
public String getHTML(String urlToRead, int responseCode) {
URL url; // The URL to read
HttpURLConnection conn; // The actual connection to the web page
BufferedReader rd; // Used to read results from the web page
String line; // An individual line of the web page HTML
String result = ""; // A long string containing all the HTML
try {
url = new URL(urlToRead);
conn = (HttpURLConnection) url.openConnection();
////optional default is GET
conn.setRequestMethod("GET");
conn.setConnectTimeout(60000); //60 secs
conn.setReadTimeout(60000); //60 secs
conn.setRequestProperty("Accept-Encoding", "identity");
conn.setRequestProperty("Accept-Charset", "UTF-8");
conn.setRequestProperty("Content-Type", "text/html, text/xml");
//add request header
conn.setRequestProperty("User-Agent", USER_AGENT);
conn.setRequestProperty("Accept-Language", "ru");
responseCode = conn.getResponseCode();
if(responseCode==200) {
rd = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
}
else{
rd = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
}
while ((line = rd.readLine()) != null) {
result += "|"+line;
}
rd.close();
} catch (Exception e) {
e.printStackTrace();
}
PageHTML=result;
return result;
}