📄 http-https client.java
字号:
Get response text from HTTP/HTTPS sites and some header data
-------
public String getResponse(String urlString) throws Exception{// -throws Exception- not -try catch- So the caller can know if any error happened
URL url = new URL(urlString);
URLConnection conn = url.openConnection();// Open connection with the server
conn.setDoInput (true);
conn.setDoOutput (true);
conn.setUseCaches (false);// No need for caching
String tempStatus = conn.getHeaderField(0);// Status field
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));// To get input returned from connection
String temp;// To read line by line string response in this temp string
StringBuffer response = new StringBuffer();// To collect all line response
while ((temp = in.readLine()) != null){
response.append(temp);
response.append("\n");
}
in.close();// Close the input reader
return response.toString();// that's the respone
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -