http協議:URL、三次握手、http請求頭信息,請求方式、響應碼信息、協議的特點、TCP、IP四層協議、OSI七層協議
content="text/html;charset=utf-8"裏面的內容就是webview加載時的參數mimetype
數據流量比較小的時候利用doGet 大的時候用doPost
post發送方式比較安全 get是通過url後面附上參數發送的
http發送請求頭髮送信息
General
Remote Address:192.168.1.106:8080
Request URL:http://192.168.1.106:8080/web/MyServlet
Request Method:POST
Status Code:200 OK
Response Headers
Content-Length:19
Content-Type:text/html;charset=utf-8
Date:Sun, 08 Nov 2015 08:45:46 GMT
Server:Apache-Coyote/1.1
Request Headers
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate
Accept-Language:zh-CN,zh;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Content-Length:21
Content-Type:application/x-www-form-urlencoded
Cookie:JSESSIONID=E83D4C4F8162B4CAD03AF8AFD5D42638
Host:192.168.1.106:8080
Origin:http://192.168.1.106:8080
Referer:http://192.168.1.106:8080/web/
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36
Form Data
name:張
age:11
httpclient通過get方式發送請求
創建httpget對象
創建httpclient對象並調用execute方式發送請求 成功後會返回response對象
判斷其類型或得響應碼是否爲200 然後利用EntityUtils獲得數據
HttpResponse response;
HttpGet httpGet = new HttpGet(url);
HttpClient httpClient = new DefaultHttpClient();
try {
response = httpClient.execute(httpGet);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
String content = EntityUtils.toString(response.getEntity());
System.out.println("content:" + content);
}
多線程下載中用到的:
1、http協議字段 Range "bytes="+start+"-"+end
2、RandomAccessFile設置吸入的位置
3、開啓線程發送網絡請求
-----------------------------7df28ac180a3e
Content-Disposition: form-data; name="file"; filename="C:\Users\born\Desktop\2012081210373.jpg"
Content-Type: image/jpeg
<二進制文件數據未顯示>
---------------------------7df28ac180a3e--
在Android中開發HTTP客戶端的一般方法:先用瀏覽器試一試,
然後看瀏覽器傳給server的request header和request body是什麼,
然後我們在開發Android的HTTP客戶端的時候也仿照這同樣的header和body設置就行了