Course review:
Servlet:java language development is run on the server
Development steps:
1. Create a servlet class
2. Overriding the Doget or Dopost method
3, running on the server
Life cycle:
1. Initialization
2. Service
3. Destruction
URL: Uniform Resource Locator, URL
OpenConnection
Today's content:
HTTP protocol: Hypertext Transfer Protocol
Common ways:
1, HttpURLConnection
2, OkHttp
HttpURLConnection Steps to use:
1. Create URL object---URL url=new url ("url");
2. Get the Connection object--httpurlconnection huc= (httpurlconnection) url.openconnection
3. Setting Information---huc.setxxx
4. Connecting------Huc.connect
5. Verification Status Response code----Huc.getresponsecode
6. Get the server response content----Huc.getinputstream
7. Close-----Disconnect
Status Response code: The response status code of the server's information
1 Opening: Message
2 Opening: Success 200:ok,206: Partial response success
3 Opening: Redirection
4 Start: Request Error 404: Page not Found
5 Start: Server Error 500: Server program crashes
URL class: Uniform Resource Locator
Practice:
Http://10.16.153.63:8080/Day26/PageStudentServlet
Please use HttpURLConnection for data acquisition.
Parameters Required:
PageIndex: Current Page
Count: Quantity
1), display the data
2), save the data in the file under the current project
HTTP protocols are commonly used:
1. Get string
2, access to resources (Pictures, audio, compressed package, etc.)
3. Post Pass parameters
OkHttp: The current comparison of Fire network framework
Steps to use:
1. Create client Object---okhttpclient client=new okhttpclient ()
2. Create Request object-----requests Request=new Request.builder (). URL ("url"). Build ()
3. Create the Response object-----Response response=client.newcall (Request). Execute ();
4. Verify success----response.issuccessful
5. Get the server response information----Response.body.XXX
Common:
Bytes: Gets the byte array corresponding to the content
String: Gets the strings for the content
ByteStream: Gets the byte array corresponding to the content
Charstream: Gets the array of characters corresponding to the content
ContentLength: Number of bytes of content
Practice:
Write an interface that requires a parameter number (8-bit)
Get request, return randomly generated phone number 13xxxx-18xxxx 11 bit
Post request, return 3-10-bit English alphabet, as English name
Require clients to initiate get and post requests
Requires the use of httpurlconnection (GET) and Okhttp (POST) implementations
Http://10.16.153.63:8080/Day27_Server/WeatherCityNo.txt
Multi-threaded Download and breakpoint continuation
Overall idea:
Distribution
Number of fixed threads
Or the size of a fixed block
"Qianfengday27-httpurlconnection,okhttpclient", multi-threaded download and breakpoint resume Basic Learning: