GET請求和POST請求有什麼區別?GET請求的參數在URL的問號後面顯示,而POST參數不在URL上;POST可以比GET請求更大的數據…一般的回答都是這樣。
public static void main(String[] args) throws IOException { // 服務器監聽端口號8081 ServerSocket serverSocket = new ServerSocket(8081); // 等待接收請求,這是一個阻塞的方法,當請求到來的時候纔會繼續向下執行 Socket socket = serverSocket.accept(); // 獲取請求內容 InputStream is = socket.getInputStream(); InputStreamReader reader = new InputStreamReader(is); // 輸出請求內容 while (true) { System.out.print((char)reader.read()); } }
<form method="get" action="http://localhost:8081"> name:<input type="text" name="name" /><br> age:<input type="text" name="age" /><br> <input type="submit" /> </form>
GET /?name=XXG&age=23 HTTP/1.1 Host: localhost:8081 Connection: keep-alive Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-CN,zh;q=0.8
POST / HTTP/1.1 Host: localhost:8081 Connection: keep-alive Content-Length: 15 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 Origin: null User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Content-Type: application/x-www-form-urlencoded Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-CN,zh;q=0.8 name=XXG&age=23
GET請求的參數在URL中,在請求的第一行Request-Line中,而POST請求的參數在請求主體Message-Body中。
轉載至:http://www.cnblogs.com/549294286/p/4665842.html