In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
The network connections API you have come into contact with are as follows:
1. HttpURLConnection
Four elements: 1, URL 2, HttpURLConnection 3, outputStream 4, inputStream
Uri.openConnection (); / / get HttpURLConnection.
Hc.setDoInput (true); / / allow input
Hc.setDoOutput (true); / / allow output
Hc.setRequestMethod ("POST"); / / set to post
Hc.setUseCaches (false); / / post does not use caching
Hc.setConnectTimeout (3000); / / set connection timeout
Hc.setReadTimeout (3000); / / set read timeout
Hc.setRequestProperty ("Content-Type", "application/x-www-form-urlencoded")
Hc.setRequestProperty ("Charset", "UTF-8")
Os = hc.getOutputStream (); / / get the output stream
Os.write (vals)
Os.flush ()
If (hc.getResponseCode () = = HttpURLConnection.HTTP_OK)
Is = hc.getInputStream (); / / get the input stream
Get HttpURLConnection through URL.
OutputStream and inputStream are obtained by HttpURLConnection.
II. HttpClient
Four elements: 1, HttpParams 2, HttpClient 3, HttpPost/HttpGet 4, HttpEntity 5, HttpResponse
BasicHttpParams httpParams = new BasicHttpParams ()
HttpConnectionParams.setConnectionTimeout (httpParams
3000)
HttpConnectionParams.setSoTimeout (httpParams,3000)
HttpClient client = new DefaultHttpClient (httpParams)
HttpPost post = new HttpPost ("http://");
Post.setHeader ()
Post.setEntity ()
HttpResponse response = client.execute (post)
If (httpResponse.getStatusLine (). GetStatusCode () = 200)
Response.getEntity ()
Note: HttpEntity should use the appropriate class
Commonly used new ByteArrayEntity (content.getBytes ("UTF-8"))
UrlEncodedFormEntity / / list of key-value pairs
Note: Content-Type
Text: for standardized representation of text information, text messages can be in multiple character sets or formats
Multipart: multiple parts used to connect the body of the message form a message, which can be different types of data
Application: used to transfer application data or binary data
Message: used to wrap an E-mail message
Image: used to transfer static picture data
Audio: used to transmit audio or audio data
Video: used to transmit moving image data, which can be a video data format edited with audio.
HTML 5 enctype attribute
The enctype attribute specifies how the form data is encoded before it is sent to the server.
Application/x-www-form-urlencoded encodes all characters before sending (default).
Multipart/form-data does not encode characters. This value is required when using a form with file upload controls.
Text/plain converts spaces to "+" symbols, but does not encode special characters.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.