---WebCam网络摄像头11 http协议
生活随笔
收集整理的這篇文章主要介紹了
---WebCam网络摄像头11 http协议
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
看一下httpd.c中關于http協議的部分
關于http協議的知識 refer to http://www.cnblogs.com/li0803/archive/2008/11/03/1324746.html
此文按照http請求應答的流程詳細講了如下:
HTTP協議詳解之URL篇
HTTP協議詳解之請求篇
HTTP協議詳解之響應篇
很感謝
這里也按照他的思路溯源一下mjpg-streamer
①HTTP協議詳解之URL篇
格式
http://host[":"port][abs_path]
比如
http//192.168.1.230:8080
http//192.168.1.230:8080/subdirectory
②HTTP協議詳解之請求篇
http請求由三部分組成,分別是:請求行、消息報頭、請求正文
請求行以一個方法符號開頭,以空格分開,后面跟著請求的URI和協議的版本,
格式如下:Method Request-URI HTTP-Version CRLF??
其中
Method表示請求方法;
Request-URI是一個統一資源標識符;
HTTP-Version表示請求的HTTP協議版本;
CRLF表示回車\r和換行\n(除了作為結尾的CRLF外,不允許出現單獨的CR或LF字符)。
比如
GET /?action=snapshot?HTTP/1.1\r\n??? <--http://192.168.1.230:8080/?action=snapshot
GET /?action=stream HTTP/1.1\r\n???? <--http://192.168.1.230:8080/?action=stream
GET /index.html HTTP/1.1\r\n????????? <--http://192.168.1.230:8080/index.html
我們只需在瀏覽器中輸入如 http://192.168.1.230:8080/?action=snapshot,瀏覽器自動會將其解釋為請求行GET /?action=snapshot?HTTP/1.1\r\n,然后發給web服務器,web服務器在收到的字符串中查找子串GET /?action=snapshot,如果找到就發送snapshot,比如在httpd.c的client_thread()函數里面有一行
/* determine what to deliver */if ( strstr(buffer, "GET /?action=snapshot") != NULL ) {req.type = A_SNAPSHOT;} 消息報頭(請求報頭)
Accept
Accept請求報頭域用于指定客戶端接受哪些類型的信息。eg:Accept:image/gif,表明客戶端希望接受GIF圖象格式的資源;Accept:text/html,表明客戶端希望接受html文本。
Accept-Charset
Accept-Charset請求報頭域用于指定客戶端接受的字符集。eg:Accept-Charset:iso-8859-1,gb2312.如果在請求消息中沒有設置這個域,缺省是任何字符集都可以接受。
Accept-Encoding
Accept-Encoding請求報頭域類似于Accept,但是它是用于指定可接受的內容編碼。eg:Accept-Encoding:gzip.deflate.如果請求消息中沒有設置這個域服務器假定客戶端對各種內容編碼都可以接受。
Accept-Language
Accept-Language請求報頭域類似于Accept,但是它是用于指定一種自然語言。eg:Accept-Language:zh-cn.如果請求消息中沒有設置這個報頭域,服務器假定客戶端對各種語言都可以接受。
Authorization
Authorization請求報頭域主要用于證明客戶端有權查看某個資源。當瀏覽器訪問一個頁面時,如果收到服務器的響應代碼為401(未授權),可以發送一個包含Authorization請求報頭域的請求,要求服務器對其進行驗證。
Host(發送請求時,該報頭域是必需的)
Host請求報頭域主要用于指定被請求資源的Internet主機和端口號,它通常從HTTP URL中提取出來的,eg:
我們在瀏覽器中輸入:http://www.guet.edu.cn/index.html
瀏覽器發送的請求消息中,就會包含Host請求報頭域,如下:
Host:www.guet.edu.cn
此處使用缺省端口號80,若指定了端口號,則變成:Host:www.guet.edu.cn:指定端口號
User-Agent
我們上網登陸論壇的時候,往往會看到一些歡迎信息,其中列出了你的操作系統的名稱和版本,你所使用的瀏覽器的名稱和版本,這往往讓很多人感到很神奇,實際上,服務器應用程序就是從User-Agent這個請求報頭域中獲取到這些信息。User-Agent請求報頭域允許客戶端將它的操作系統、瀏覽器和其它屬性告訴服務器。不過,這個報頭域不是必需的,如果我們自己編寫一個瀏覽器,不使用User-Agent請求報頭域,那么服務器端就無法得知我們的信息了。
具體例子見下面測試
③HTTP協議詳解之響應篇
Status-Code表示服務器發回的響應狀態代碼;
Reason-Phrase表示狀態代碼的文本描述。
CRLF:除實體主體外所有協議元素的行結束標志。CR回車\r,LF換行\n
比如
HTTP/1.0 200 OK\r\n
2..消息報頭(響應報頭)在httpd.h中定義
#define STD_HEADER "Connection: close\r\n" \
?????????????????? "Server: MJPG-Streamer/0.2\r\n" \
?????????????????? "Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0\r\n" \
?????????????????? "Pragma: no-cache\r\n" \
?????????????????? "Expires: Mon, 3 Jan 2000 12:34:56 GMT\r\n"
3.實體報頭即mimetype
用于向瀏覽器說明實體正文的類型
?比如"Content-type: image/jpeg\r\n" \
實體正文
比如jpg格式的圖像數據
看一下httpd.c在響應瀏覽器請求時,發送了怎樣的狀態行 消息報頭 實體報頭.
先貼出 STD_HEADER
httpd.h
#define STD_HEADER "Connection: close\r\n" \"Server: MJPG-Streamer/0.2\r\n" \"Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0\r\n" \"Pragma: no-cache\r\n" \"Expires: Mon, 3 Jan 2000 12:34:56 GMT\r\n"
1.case A_SNAPSHOT:
/****************************************************************************** Description.: Send a complete HTTP response and a single JPG-frame. Input Value.: fildescriptor fd to send the answer to Return Value: - ******************************************************************************/ void send_snapshot(int fd) {unsigned char *frame=NULL;int frame_size=0;char buffer[BUFFER_SIZE] = {0};/* wait for a fresh frame */pthread_cond_wait(&pglobal->db_update, &pglobal->db);/* read buffer */frame_size = pglobal->size;/* allocate a buffer for this single frame */if ( (frame = malloc(frame_size+1)) == NULL ) {free(frame);pthread_mutex_unlock( &pglobal->db );send_error(fd, 500, "not enough memory");return;}memcpy(frame, pglobal->buf, frame_size);DBG("got frame (size: %d kB)\n", frame_size/1024);pthread_mutex_unlock( &pglobal->db );/* write the response */sprintf(buffer, "HTTP/1.0 200 OK\r\n" \ //狀態行STD_HEADER \ //響應報頭"Content-type: image/jpeg\r\n" \ //實體報頭,圖像"\r\n");/* send header and image now */if( write(fd, buffer, strlen(buffer)) < 0 || \write(fd, frame, frame_size) < 0) { //實體正文free(frame);return;}free(frame); } 2.case A_STREAM:
/****************************************************************************** Description.: Send a complete HTTP response and a stream of JPG-frames. Input Value.: fildescriptor fd to send the answer to Return Value: - ******************************************************************************/ void send_stream(int fd) {unsigned char *frame=NULL, *tmp=NULL;int frame_size=0, max_frame_size=0;char buffer[BUFFER_SIZE] = {0};DBG("preparing header\n");sprintf(buffer, "HTTP/1.0 200 OK\r\n" \ //狀態行STD_HEADER \ //響應報頭"Content-Type: multipart/x-mixed-replace;boundary=" BOUNDARY "\r\n" \ //實體報頭,后續還有"\r\n" \"--" BOUNDARY "\r\n");if ( write(fd, buffer, strlen(buffer)) < 0 ) {free(frame);return;}DBG("Headers send, sending stream now\n");while ( !pglobal->stop ) {/* wait for fresh frames */pthread_cond_wait(&pglobal->db_update, &pglobal->db);/* read buffer */frame_size = pglobal->size;/* check if framebuffer is large enough, increase it if necessary */if ( frame_size > max_frame_size ) {DBG("increasing buffer size to %d\n", frame_size);max_frame_size = frame_size+TEN_K;if ( (tmp = realloc(frame, max_frame_size)) == NULL ) {free(frame);pthread_mutex_unlock( &pglobal->db );send_error(fd, 500, "not enough memory");return;}frame = tmp;}memcpy(frame, pglobal->buf, frame_size);DBG("got frame (size: %d kB)\n", frame_size/1024);pthread_mutex_unlock( &pglobal->db );/** print the individual mimetype and the length* sending the content-length fixes random stream disruption observed* with firefox*/sprintf(buffer, "Content-Type: image/jpeg\r\n" \"Content-Length: %d\r\n" \"\r\n", frame_size); //實體報頭DBG("sending intemdiate header\n");if ( write(fd, buffer, strlen(buffer)) < 0 ) break;DBG("sending frame\n");if( write(fd, frame, frame_size) < 0 ) break; //實體正文DBG("sending boundary\n");sprintf(buffer, "\r\n--" BOUNDARY "\r\n");if ( write(fd, buffer, strlen(buffer)) < 0 ) break;}free(frame); }3.case A_FILE:
/****************************************************************************** Description.: Send HTTP header and copy the content of a file. To keep thingssimple, just a single folder gets searched for the file. Justfiles with known extension and supported mimetype get served.If no parameter was given, the file "index.html" will be copied. Input Value.: * fd.......: filedescriptor to send data to* parameter: string that consists of the filename* id.......: specifies which server-context is the right one Return Value: - ******************************************************************************/ void send_file(int id, int fd, char *parameter) {char buffer[BUFFER_SIZE] = {0};char *extension, *mimetype=NULL;int i, lfd;config conf = servers[id].conf;/* in case no parameter was given */if ( parameter == NULL || strlen(parameter) == 0 )parameter = "index.html";/* find file-extension */if ( (extension = strstr(parameter, ".")) == NULL ) {send_error(fd, 400, "No file extension found");return;}/* determine mime-type */for ( i=0; i < LENGTH_OF(mimetypes); i++ ) {if ( strcmp(mimetypes[i].dot_extension, extension) == 0 ) { /* mimetypes定義在httpd.h,過濾文件的后擴展名 static const struct {const char *dot_extension;const char *mimetype; } mimetypes[] = {{ ".html", "text/html" },{ ".htm",? "text/html" },{ ".css",? "text/css" },{ ".js",?? "text/javascript" },{ ".txt",? "text/plain" },{ ".jpg",? "image/jpeg" },{ ".jpeg", "image/jpeg" },{ ".png",? "image/png"},{ ".gif",? "image/gif" },{ ".ico",? "image/x-icon" },{ ".swf",? "application/x-shockwave-flash" },{ ".cab",? "application/x-shockwave-flash" },{ ".jar",? "application/java-archive" } }; 所以按照這個mimetypes,客戶瀏覽器訪問 http://192.168.1.230:8080/test.cgi 時,服務器就會返回下面的404錯誤 如果加上下面一行,使支持cgi { ".cgi", "magnus-internal/cgi" },但實驗中,瀏覽器直接彈出一個保存對話框。。。原因待查。。。 如果是{ ".cgi", "text/html" },輸出是亂碼使支持瀏覽器在線打開pdf { ".pdf", "application/pdf" },可以。 各個mimetype(content-type) http://blog.csdn.net/fanweiwei/article/details/1787747 */mimetype = (char *)mimetypes[i].mimetype;break;}}/* in case of unknown mimetype or extension leave */if ( mimetype == NULL ) {send_error(fd, 404, "MIME-TYPE not known");return;}/* now filename, mimetype and extension are known */DBG("trying to serve file \"%s\", extension: \"%s\" mime: \"%s\"\n", parameter, extension, mimetype);/* build the absolute path to the file */strncat(buffer, conf.www_folder, sizeof(buffer)-1);strncat(buffer, parameter, sizeof(buffer)-strlen(buffer)-1);/* try to open that file */if ( (lfd = open(buffer, O_RDONLY)) < 0 ) {DBG("file %s not accessible\n", buffer);send_error(fd, 404, "Could not open file");return;}DBG("opened file: %s\n", buffer);/* prepare HTTP header */sprintf(buffer, "HTTP/1.0 200 OK\r\n" \ //狀態行"Content-type: %s\r\n" \STD_HEADER \ //響應報頭"\r\n", mimetype); //實體報頭。可將"Content-type: %s\r\n" 放在STD_HEADER后面。i = strlen(buffer);/* first transmit HTTP-header, afterwards transmit content of file */do {if ( write(fd, buffer, i) < 0 ) { //實體正文close(lfd);return;}} while ( (i=read(lfd, buffer, sizeof(buffer))) > 0 );/* close file, job done */close(lfd); }
以下是 在firefox瀏覽器中輸入
http://192.168.1.230:8080/?action=snapshot
之后抓取的所有相關的包,192.168.1.101(client)<-->192.168.1.230(webserver)
圖1
有兩個關鍵的tcp報文--協議是http的
NO 6和NO 21
NO 6就是對應瀏覽器向webserver請求時發送的數據,包括請求行和請求報頭,共計401字節,具體如下
圖2
NO 21對應webserver返回的數據的一部分,72字節。和其他9個tcp報文共同組成一個http報文。即圖1黑的底色的標記的部分,共計10個tcp報文。
為什么要將一個http的數據分開?又為什么要分成10個?
因為數據鏈路層的以太網幀的數據部分最大是1500字節,然后再加上14個字節的以太網頭部---所以是1514字節--和圖1的NO9 11 12 14 15 17 18 20幀的長度對應。
所以在webserver上的http層將數據交給tcp再給ip再給數據鏈路層時,會將ip層下來的數據分片,每片最大1500+14字節。所以分成了若干個。
然后在客戶端接收時,在ip層會將分片的其組裝起來然后再交給http層。
圖3
其實仔細看一下可以知道,狀態行和響應報頭的數據是在NO 8里面的
圖4
NO9 11 12 14 15 17 18 20 21對應實體正文,即圖像數據
看一下圖像數據,
NO 9
0000 00 22 fa 7b 9b 76 08 90 90 90 90 90 08 00 45 00 .".{.v.. ......E. 0010 05 dc 9d c2 40 00 40 06 12 be c0 a8 01 e6 c0 a8 ....@.@. ........ 0020 01 65 1f 90 05 d7 4b f6 31 0b 3a a2 68 46 50 10 .e....K. 1.:.hFP. 0030 19 20 17 85 00 00 ff d8 ff db 00 84 00 10 0b 0c . ...... ........ 0040 0e 0c 0a 10 0e 0d 0e 12 11 10 13 18 28 1a 18 16 ........ ....(... 0050 16 18 31 23 25 1d 28 3a 33 3d 3c 39 33 38 37 40 ..1#%.(: 3=<9387@ 0060 48 5c 4e 40 44 57 45 37 38 50 6d 51 57 5f 62 67 H\N@DWE7 8PmQW_bg 0070 68 67 3e 4d 71 79 70 64 78 5c 65 67 63 01 11 12 hg>Mqypd x\egc... 0080 12 18 15 18 2f 1a 1a 2f 63 42 38 42 63 63 63 63 ..../../ cB8Bcccc 0090 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 cccccccc cccccccc 00a0 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 cccccccc cccccccc 00b0 63 63 63 63 63 63 63 63 63 63 63 63 63 63 ff c4 cccccccc cccccc.. 00c0 01 a2 00 00 01 05 01 01 01 01 01 01 00 00 00 00 ........ ........ 00d0 00 00 00 00 01 02 03 04 05 06 07 08 09 0a 0b 01 ........ ........ 00e0 00 03 01 01 01 01 01 01 01 01 01 00 00 00 00 00 ........ ........ 00f0 00 01 02 03 04 05 06 07 08 09 0a 0b 10 00 02 01 ........ ........ 0100 03 03 02 04 03 05 05 04 04 00 00 01 7d 01 02 03 ........ ....}... 0110 00 04 11 05 12 21 31 41 06 13 51 61 07 22 71 14 .....!1A ..Qa."q. 0120 32 81 91 a1 08 23 42 b1 c1 15 52 d1 f0 24 33 62 2....#B. ..R..$3b 0130 72 82 09 0a 16 17 18 19 1a 25 26 27 28 29 2a 34 r....... .%&'()*4 0140 35 36 37 38 39 3a 43 44 45 46 47 48 49 4a 53 54 56789:CD EFGHIJST 0150 55 56 57 58 59 5a 63 64 65 66 67 68 69 6a 73 74 UVWXYZcd efghijst 0160 75 76 77 78 79 7a 83 84 85 86 87 88 89 8a 92 93 uvwxyz.. ........ 0170 94 95 96 97 98 99 9a a2 a3 a4 a5 a6 a7 a8 a9 aa ........ ........ 0180 b2 b3 b4 b5 b6 b7 b8 b9 ba c2 c3 c4 c5 c6 c7 c8 ........ ........ 0190 c9 ca d2 d3 d4 d5 d6 d7 d8 d9 da e1 e2 e3 e4 e5 ........ ........ 01a0 e6 e7 e8 e9 ea f1 f2 f3 f4 f5 f6 f7 f8 f9 fa 11 ........ ........ 01b0 00 02 01 02 04 04 03 04 07 05 04 04 00 01 02 77 ........ .......w 01c0 00 01 02 03 11 04 05 21 31 06 12 41 51 07 61 71 .......! 1..AQ.aq 01d0 13 22 32 81 08 14 42 91 a1 b1 c1 09 23 33 52 f0 ."2...B. ....#3R. 01e0 15 62 72 d1 0a 16 24 34 e1 25 f1 17 18 19 1a 26 .br...$4 .%.....& 01f0 27 28 29 2a 35 36 37 38 39 3a 43 44 45 46 47 48 '()*5678 9:CDEFGH 0200 49 4a 53 54 55 56 57 58 59 5a 63 64 65 66 67 68 IJSTUVWX YZcdefgh 0210 69 6a 73 74 75 76 77 78 79 7a 82 83 84 85 86 87 ijstuvwx yz...... 0220 88 89 8a 92 93 94 95 96 97 98 99 9a a2 a3 a4 a5 ........ ........ 0230 a6 a7 a8 a9 aa b2 b3 b4 b5 b6 b7 b8 b9 ba c2 c3 ........ ........ 0240 c4 c5 c6 c7 c8 c9 ca d2 d3 d4 d5 d6 d7 d8 d9 da ........ ........ 0250 e2 e3 e4 e5 e6 e7 e8 e9 ea f2 f3 f4 f5 f6 f7 f8 ........ ........ 0260 f9 fa ff c0 00 11 08 01 e0 02 80 03 01 21 00 02 ........ .....!.. 0270 11 01 03 11 01 ff da 00 0c 03 01 00 02 11 03 11 ........ ........ 0280 00 3f 00 ea 68 c5 59 21 40 a0 02 96 80 0c 50 05 .?..h.Y! @.....P. 0290 20 16 8c 50 02 62 8c 50 30 c5 18 a0 05 02 8c 52 ..P.b.P 0......R 02a0 10 b8 a4 c5 00 18 a7 0a 60 38 52 8a 43 16 8c 50 ........ `8R.C..P 02b0 03 94 52 95 a0 06 11 8a 50 73 54 88 68 8a 58 f2 ..R..... PsT.h.X. 02c0 2a b0 8b 0f 44 b4 08 32 f4 23 0a 2a 4c 54 22 c5 *...D..2 .#.*LT". 02d0 03 8a 4c 53 18 1a 41 40 87 01 52 0a 06 2e 28 a4 ..LS..A@ ..R...(. 02e0 01 45 30 0a 28 01 28 a4 02 1a 43 40 0d e9 48 68 .E0.(.(. ..C@..Hh 02f0 01 a6 b3 dc 6d ba 7f f6 b9 a0 68 92 90 d2 00 c5 ....m... ..h..... 0300 34 50 02 9a 70 1c 53 10 50 45 00 03 8a 0f 5a 04 4P..p.S. PE....Z. 0310 14 62 80 00 29 d8 a6 21 08 a6 1a 43 0a 5a 60 25 .b..)..! ...C.Z`% 0320 25 00 14 b8 a4 31 0d 36 80 15 69 d8 a0 03 14 86 %....1.6 ..i..... 0330 81 12 d1 56 21 3a d2 d0 08 4a 29 00 e0 29 68 01 ...V!:.. .J)..)h. 0340 28 a0 62 d0 28 10 62 8a 06 18 a5 a4 01 8a 31 40 (.b.(.b. ......1@ 0350 06 29 45 00 38 0a 5a 00 5a 28 01 ea 29 d4 00 15 .)E.8.Z. Z(..)... 0360 cd 44 57 14 5c 2c 2e 32 39 a6 f9 5c d3 93 ba 12 .DW.\,.2 9..\.... 0370 56 64 c8 b8 a7 62 a5 6c 50 a0 52 1a 60 34 8a 40 Vd...b.l P.R.`4.@ 0380 28 01 c2 9c 0e 28 01 c2 8a 00 29 69 00 94 53 00 (....(.. ..)i..S. 0390 a4 34 00 94 94 80 6b 52 01 40 08 45 50 bc 1b 66 .4....kR .@.EP..f 03a0 8d bd 4e 28 1a 1c 39 14 94 80 0d 20 a0 02 9c 3a ..N(..9. ... ...: 03b0 53 10 52 f6 a0 42 51 40 05 2d 30 0a 70 a0 04 35 S.R..BQ@ .-0.p..5 03c0 19 34 02 01 4b 40 08 68 a0 00 52 d2 01 29 b4 0c .4..K@.h ..R..).. 03d0 05 3c 50 02 d3 4d 02 1e 29 6a c4 2e 29 29 00 50 .<P..M.. )j..)).P 03e0 28 b0 0b 4b 40 05 14 00 b4 50 30 a5 c5 20 0a 31 (..K@... .P0.. .1 03f0 40 0b 46 28 01 71 48 28 01 c2 94 0a 00 5c 52 81 @.F(.qH( .....\R. 0400 40 0e 02 9d 8a 06 28 a3 14 00 9b 69 71 4a c0 14 @.....(. ...iqJ.. 0410 b4 c0 5a 42 28 01 29 28 00 a7 0a 00 70 a5 a4 02 ..ZB(.)( ....p... 0420 52 d3 01 05 14 80 29 bd e9 80 b4 86 90 0c 34 50 R.....). ......4P 0430 00 6a 96 a0 bf bb 0d dd 48 a0 68 62 f4 a5 a4 02 .j...... H.hb.... 0440 52 0e 28 01 69 45 31 08 69 45 08 02 96 84 21 28 R.(.iE1. iE....!( 0450 14 00 ea 05 30 11 aa 33 48 10 ab 4a 69 80 94 94 ....0..3 H..Ji... 0460 80 51 4a 28 01 0d 14 00 94 e1 40 0b 4d 34 00 f1 .QJ(.... ..@.M4.. 0470 4b 9a b6 20 cd 14 80 29 45 00 14 a2 81 8b 8a 28 K.. ...) E......( 0480 10 52 8a 43 17 14 62 80 16 93 14 00 b8 a5 02 80 .R.C..b. ........ 0490 16 9a c3 14 20 14 53 85 00 3a 94 50 03 85 38 0a .... .S. .:.P..8. 04a0 06 18 a2 80 14 51 8a 00 31 4b 48 02 8c 50 03 68 .....Q.. 1KH..P.h 04b0 c5 30 0c 52 e2 90 0a 29 68 00 a4 ed 4c 02 96 90 .0.R...) h...L... 04c0 08 68 a0 04 a4 34 00 c6 1c 52 01 40 c4 39 a8 2e .h...4.. .R.@.9.. 04d0 13 74 4c 3d a9 02 2b 42 72 8a 7d aa 43 40 0d a2 .tL=..+B r.}.C@.. 04e0 80 16 80 79 a6 21 69 28 00 a5 ed 40 09 4b 40 85 ...y.!i( ...@.K@. 04f0 a2 80 10 f4 a6 62 80 42 8a 29 80 94 94 80 51 4b .....b.B .)....QK 0500 40 01 a4 a0 04 a5 14 0c 75 34 d0 21 e2 96 ac 41 @....... u4.!...A 0510 45 20 16 8a 00 50 28 e9 40 0b 40 a4 31 68 a0 05 E ...P(. @.@.1h.. 0520 14 b4 00 b4 94 00 a2 96 80 0a 08 e2 80 11 69 e2 ........ ......i. 0530 81 8e 02 8a 00 70 a7 0a 00 5a 28 00 14 b4 00 51 .....p.. .Z(....Q 0540 48 02 8a 60 21 a4 c5 00 2d 14 00 b4 b4 00 52 50 H..`!... -.....RP 0550 02 d1 40 09 45 20 12 90 d0 31 29 28 01 2a 29 46 ..@.E .. .1)(.*)F 0560 54 8a 4c 0a 10 f1 95 f4 38 a9 73 40 30 a4 c5 00 T.L..... 8.s@0... 0570 2f 6a 28 10 50 29 80 b4 94 00 82 9e 28 10 51 da /j(.P).. ....(.Q. 0580 98 05 30 d2 01 05 2d 30 12 8a 00 51 45 00 21 a4 ..0...-0 ...QE.!. 0590 a4 30 a5 14 00 b4 50 21 e3 a5 21 aa 10 50 29 80 .0....P! ..!..P). 05a0 ea 29 00 52 e2 80 17 14 bd a9 0c 05 28 a0 00 52 .).R.... ....(..R 05b0 d0 02 d1 40 0b 4a 28 18 b4 98 a0 43 71 83 52 2d ...@.J(. ...Cq.R- 05c0 0c 07 52 e3 34 0c 50 29 69 00 b4 53 01 69 28 01 ..R.4.P) i..S.i(. 05d0 68 a4 01 45 00 14 62 98 09 8a 5a 00 29 69 00 52 h..E..b. ..Z.)i.R 05e0 62 80 16 8a 00 4a 43 40 00 14 b....JC@ .. NO 10
0000 00 22 fa 7b 9b 76 08 90 90 90 90 90 08 00 45 00 .".{.v.. ......E. 0010 05 dc 9d c3 40 00 40 06 12 bd c0 a8 01 e6 c0 a8 ....@.@. ........ 0020 01 65 1f 90 05 d7 4b f6 36 bf 3a a2 68 46 50 10 .e....K. 6.:.hFP. 0030 19 20 7e cc 00 00 94 00 1a 61 a0 04 a6 b0 c8 e6 . ~..... .a...... 0040 90 cc f3 c5 cb 8e c7 91 52 52 01 0d 2d 31 00 a2 ........ RR..-1.. 0050 80 10 d2 8e 69 80 b4 62 80 13 1c d3 a8 42 12 81 ....i..b .....B.. 0060 40 05 21 a0 06 d1 40 c2 8a 62 01 4b 48 02 8a 06 @.!...@. .b.KH... 0070 25 14 08 5a 43 d2 80 1d 4a 2a c4 2e 28 a4 00 29 %..ZC... J*..(..) 0080 68 18 b4 b4 08 5a 28 18 52 d2 00 14 e1 40 21 68 h....Z(. R....@!h 0090 a0 05 a6 96 c5 08 18 6f a7 83 9a 01 01 14 ab d2 .......o ........ 00a0 81 8e 14 e1 40 0b 4b 40 05 14 00 a2 8a 40 14 50 ....@.K@ .....@.P 00b0 00 29 68 01 29 68 00 a4 a0 05 a4 a0 05 a2 80 13 .)h.)h.. ........ 00c0 34 50 01 45 00 34 b6 29 68 01 a6 98 68 00 a6 13 4P.E.4.) h...h... 00d0 48 65 19 c6 db a5 3e a2 9f d4 52 e8 02 76 a0 1a He....>. ..R..v.. 00e0 60 03 ad 19 a1 00 a6 81 c5 02 16 81 4c 00 d2 66 `....... ....L..f 00f0 80 0a 5a 04 2d 25 30 1b 45 00 04 52 50 02 0a 75 ..Z.-%0. E..RP..u 0100 20 0a 28 00 a2 80 0a 0d 00 3a 8a a1 0a 28 c5 00 .(..... .:...(.. 0110 14 a2 81 8e a0 52 10 52 d0 30 a5 14 00 b4 a2 80 .....R.R .0...... 0120 14 52 d0 30 c5 31 93 34 08 55 5a 78 14 90 c5 ed .R.0.1.4 .UZx.... 0130 48 bc 53 01 c2 9c 29 00 a2 8a 60 3a 81 40 05 28 H.S...). ..`:.@.( 0140 a4 01 45 00 14 b4 00 94 b4 00 52 01 40 06 29 45 ..E..... ..R.@.)E 0150 00 14 50 02 62 90 f4 e2 80 11 72 07 27 34 a6 98 ..P.b... ..r.'4.. 0160 09 91 45 20 03 4c 26 80 12 98 69 01 4e f0 60 a3 ..E .L&. ..i.N.`. 0170 7a 1c 52 0e 94 ba 14 2f 6a 05 31 05 14 00 b4 50 z.R..../ j.1....P 0180 21 45 28 a6 02 1a 6e 28 01 45 14 00 ea 29 92 34 !E(...n( .E...).4 0190 d2 50 30 a4 34 02 10 53 85 21 b1 69 28 b0 84 a5 .P0.4..S .!.i(... 01a0 14 00 b4 1a 00 5a 2a 84 14 a2 80 0a 5a 43 16 96 .....Z*. ....ZC.. 01b0 80 0a 28 01 69 45 00 2d 2d 20 14 52 d3 18 b4 50 ..(.iE.- - .R...P 01c0 21 68 a0 62 8a 46 14 00 a2 9e 29 00 a0 52 e2 98 !h.b.F.. ..)..R.. 01d0 06 28 a0 05 a3 a5 20 16 8a 00 28 a0 02 8a 00 28 .(.... . ..(....( 01e0 a0 02 92 98 0b 45 00 25 18 a0 04 c5 06 90 09 40 .....E.% .......@ 01f0 a0 00 f4 a6 91 40 c6 9a 6e 29 01 5e f5 37 40 71 .....@.. n).^.7@q 0200 db 9a 89 7a 52 0e 81 4a 29 80 98 a2 80 17 a0 a4 ...zR..J )....... 0210 cd 31 0e 06 96 81 01 a6 50 31 69 45 02 14 51 4c .1...... P1iE..QL 0220 18 da 29 00 86 9b 40 00 a7 0a 01 8b 49 40 09 4a ..)...@. ....I@.J 0230 28 01 d4 86 98 0a 0d 14 c4 14 0a 06 38 51 40 05 (....... ....8Q@. 0240 3a 90 05 14 00 b4 ec 50 01 4a 28 18 b4 a2 81 0b :......P .J(..... 0250 4b 40 05 14 0c 5a 0f 4a 10 81 4f 6a 78 a0 62 d2 K@...Z.J ..Ojx.b. 0260 8a 00 28 a0 05 14 52 00 a2 80 0a 05 00 2d 14 00 ..(...R. .....-.. 0270 51 40 05 14 00 51 40 05 21 a0 02 90 d0 02 66 8a Q@...Q@. !.....f. 0280 06 25 34 d2 01 29 0d 00 47 30 0d 0b 0a a7 11 f9 .%4..).. G0...... 0290 07 d2 90 0e cd 14 c0 5a 4a 04 2f 6a 6d 00 28 a7 .......Z J./jm.(. 02a0 8a 60 06 9a 68 01 45 14 08 5a 28 01 28 a6 02 1a .`..h.E. .Z(.(... 02b0 69 14 00 01 4a 29 00 b4 86 80 12 94 50 03 a9 0d i...J).. ....P... 02c0 00 02 96 a8 41 4b 40 c3 34 a2 80 0c 52 8a 40 2d ....AK@. 4...R.@- 02d0 14 00 a2 9c 28 01 69 68 18 b4 50 21 45 14 0c 5a ....(.ih ..P!E..Z 02e0 51 40 0b 46 28 01 ac 31 cd 28 34 00 f1 4a 29 00 Q@.F(..1 .(4..J). 02f0 b4 b9 a6 01 4b 40 09 45 20 0a 05 30 16 8a 40 14 ....K@.E ..0..@. 0300 94 00 52 d0 02 51 40 05 25 00 14 1a 06 25 21 3e ..R..Q@. %....%!> 0310 94 08 4a 31 40 c6 e6 9a 79 a4 02 11 f2 e2 a8 20 ..J1@... y...... 0320 c1 61 e8 4d 01 d0 93 b5 20 a1 00 b4 94 08 51 49 .a.M.... .....QI 0330 40 00 e9 4e 5a 62 1c 7a 54 7d e8 18 e1 4b 40 85 @..NZb.z T}...K@. 0340 14 94 c1 09 45 02 12 92 90 c1 69 68 00 a6 9a 01 ....E... ..ih.... 0350 09 4e 14 0c 5a 43 40 85 a2 a8 48 5a 5a 06 14 b4 .N..ZC@. ..HZZ... 0360 00 b4 52 01 45 27 7a 00 78 a5 14 00 b4 a2 80 16 ..R.E'z. x....... 0370 81 40 c5 a5 14 08 5a 28 18 b4 b4 00 84 71 48 94 .@....Z( .....qH. 0380 00 f0 69 d4 00 98 a5 c5 00 28 a2 80 0a 31 48 02 ..i..... .(...1H. 0390 81 40 0b 45 00 25 19 f4 a0 00 0a 28 00 a0 50 00 .@.E.%.. ...(..P. 03a0 69 bd e8 00 a3 34 0c 29 09 a0 43 72 29 09 34 00 i....4.) ..Cr).4. 03b0 d0 32 69 c1 69 0c 43 54 24 c2 ce e3 b9 39 a0 05 .2i.i.CT $....9.. 03c0 1d 28 a0 03 b5 14 00 0a 0d 02 01 d2 95 4d 30 63 .(...... .....M0c 03d0 fa 8a 66 28 b8 85 51 4a 68 00 14 50 02 51 40 08 ..f(..QJ h..P.Q@. 03e0 45 14 00 0a 5a 00 43 4d 34 00 82 9c 29 a0 16 9a E...Z.CM 4...)... 03f0 4d 20 16 8a a0 01 4e a0 05 14 b4 80 29 45 00 2d M ....N. ....)E.- 0400 2d 00 28 a5 a0 05 14 b4 00 a2 96 81 80 a7 62 80 -.(..... ......b. 0410 0c 52 d0 02 62 9c 29 00 53 0f 06 98 0f a5 14 00 .R..b.). S....... 0420 ea 28 00 a0 8a 00 00 a7 52 00 a4 a0 02 8a 00 42 .(...... R......B 0430 28 14 c0 75 26 69 00 51 40 09 48 45 00 14 0a 06 (..u&i.Q @.HE.... 0440 21 a6 31 39 a0 43 73 49 9a 00 95 17 8c 9a 18 d0 !.19.CsI ........ 0450 04 64 d5 0b 90 56 e5 5b fb c2 91 48 51 4b 9a 04 .d...V.[ ...HQK.. 0460 25 28 a0 18 b4 1e 28 10 0a 4a 00 92 9a 69 80 2f %(....(. .J...i./ 0470 4a 28 00 5a 5a 04 36 8a 00 51 45 30 12 96 80 12 J(.ZZ.6. .QE0.... 0480 9a 69 00 52 8a 60 2d 31 a9 00 ea 3b 55 00 52 83 .i.R.`-1 ...;U.R. 0490 40 0e 14 a2 90 05 28 a0 07 51 40 0a 29 68 01 45 @.....(. .Q@.)h.E 04a0 2d 00 2d 28 a0 61 4e cd 02 0c d2 d0 31 45 14 00 -.-(.aN. ....1E.. 04b0 53 58 71 40 0a 87 23 14 ea 40 28 e6 96 80 16 8a SXq@..#. .@(..... 04c0 60 26 69 41 a0 02 81 48 02 98 cd 8a 60 22 b6 4d `&iA...H ....`".M 04d0 48 3a 50 02 d1 48 06 96 e7 14 a2 80 0a 69 34 00 H:P..H.. .....i4. 04e0 94 66 80 03 4c a0 60 17 34 f5 40 39 34 20 06 3c .f..L.`. 4.@94 .< 04f0 71 4c 3d 28 01 b5 4e fb 84 56 ee 0d 20 43 07 4a qL=(..N. .V.. C.J 0500 51 cd 03 61 40 34 08 50 69 cd c8 a0 48 68 34 b4 Q..a@4.P i...Hh4. 0510 00 fc f1 4c 26 80 14 74 a2 98 85 02 8a 00 31 49 ...L&..t ......1I 0520 8a 2c 01 45 30 0a 4a 40 14 d3 40 09 4a 28 18 66 .,.E0.J@ ..@.J(.f 0530 90 d0 02 d0 2a 84 14 a3 8a 40 38 1a 5a 00 05 38 ....*... .@8.Z..8 0540 50 03 b3 45 00 28 a5 a0 05 a5 14 00 b4 b4 0c 29 P..E.(.. .......) 0550 45 02 16 96 81 85 2e 68 00 cd 14 00 c1 f2 bf b1 E......h ........ 0560 a9 48 a0 05 5e 94 b4 00 52 13 40 00 1c d2 d2 00 .H..^... R.@..... 0570 a4 a0 05 a6 95 cd 03 14 20 1d 29 45 00 14 99 a0 ........ .)E.... 0580 41 8c d0 28 01 6a 2c ee 27 1d a8 01 68 a0 02 9a A..(.j,. '...h... 0590 68 01 47 02 9e 4f 14 00 da 42 28 18 d2 2a b5 da h.G..O.. .B(..*.. 05a0 e6 16 1d e9 31 ad ca d1 9d c8 0f b5 38 71 40 0e ....1... ....8q@. 05b0 14 94 08 3a 1a 77 6a 04 20 14 a6 86 31 45 21 14 ...:.wj. ...1E!. 05c0 08 55 e9 4b 4c 40 3a d1 40 01 a0 50 02 52 50 00 .U.KL@:. @..P.RP. 05d0 29 68 01 0d 21 a0 06 d1 40 c2 83 40 85 a2 a8 05 )h..!... @..@.... 05e0 a6 39 c5 08 01 1e a6 07 8a 91 .9...... ..
下面是瀏覽器中輸入
http://192.168.1.230:8080/static.html
之后的相關http包
static.html 的源碼如下
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><title>MJPG-streamer</title><meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /><link rel="stylesheet" href="style.css" type="text/css" /><!--[if IE 6]><link rel="stylesheet" href="fix.css" type="text/css" /><![endif]--></head><body><div id="sidebar"><h1>MJPG-Streamer Demo Pages</h1><h2>a ressource friendly streaming application</h2><div id="menu"><a href="index.html">Home</a><a class="active" href="static.html">Static</a> <a href="stream.html">Stream</a> <a href="java.html">Java</a> <a href="javascript.html">Javascript</a><a href="videolan.html">VideoLAN</a><a target="_blank" onClick="window.open(this.href, '_blank','width=400,height=400'); return false;" href="control.htm">Control</a></div><h3>Version info:</h3><p>v0.1 (Okt 22, 2007)</p></div><div id="content"><h1>Static</h1><h2>A static snapshot</h2><h3>Hints</h3><p>This example shows a static snapshot. It should work with any browser. To see a simple example click <a href="static_simple.html">here</a>.</p><h3>Source snippet</h3><p><pre><img src="/?action=snapshot" /></pre></p><img src="/?action=snapshot" alt="This is a static snapshot" width="512px" height="384px" /><p>? The <a href="http://mjpg-streamer.sf.net">MJPG-streamer team</a> | Design by <a href="http://andreasviklund.com">Andreas Viklund</a></p></div></body> </html> 根據源碼和抓取的包中若干GET方法可以推斷整個過程:
1.瀏覽器首先根據地址欄里的/static.html,發送一個GET/static.html HTTP/1.1請求。然后服務器響應,將static,html發出
2.瀏覽器依次解釋static.html的html標記,以便將static.html的內容顯示出來。
3.解釋到line 7,會發送GET /style.css HTTP/1.1請求。以獲取style.css文件。
4.解釋到line 44,會發送GET /?action=snapshot請求,以獲取圖像數據。
關于http協議的知識 refer to http://www.cnblogs.com/li0803/archive/2008/11/03/1324746.html
此文按照http請求應答的流程詳細講了如下:
HTTP協議詳解之URL篇
HTTP協議詳解之請求篇
HTTP協議詳解之響應篇
很感謝
這里也按照他的思路溯源一下mjpg-streamer
①HTTP協議詳解之URL篇
格式
http://host[":"port][abs_path]
比如
http//192.168.1.230:8080
http//192.168.1.230:8080/subdirectory
②HTTP協議詳解之請求篇
http請求由三部分組成,分別是:請求行、消息報頭、請求正文
請求行以一個方法符號開頭,以空格分開,后面跟著請求的URI和協議的版本,
格式如下:Method Request-URI HTTP-Version CRLF??
其中
Method表示請求方法;
Request-URI是一個統一資源標識符;
HTTP-Version表示請求的HTTP協議版本;
CRLF表示回車\r和換行\n(除了作為結尾的CRLF外,不允許出現單獨的CR或LF字符)。
比如
GET /?action=snapshot?HTTP/1.1\r\n??? <--http://192.168.1.230:8080/?action=snapshot
GET /?action=stream HTTP/1.1\r\n???? <--http://192.168.1.230:8080/?action=stream
GET /index.html HTTP/1.1\r\n????????? <--http://192.168.1.230:8080/index.html
我們只需在瀏覽器中輸入如 http://192.168.1.230:8080/?action=snapshot,瀏覽器自動會將其解釋為請求行GET /?action=snapshot?HTTP/1.1\r\n,然后發給web服務器,web服務器在收到的字符串中查找子串GET /?action=snapshot,如果找到就發送snapshot,比如在httpd.c的client_thread()函數里面有一行
/* determine what to deliver */if ( strstr(buffer, "GET /?action=snapshot") != NULL ) {req.type = A_SNAPSHOT;} 消息報頭(請求報頭)
Accept
Accept請求報頭域用于指定客戶端接受哪些類型的信息。eg:Accept:image/gif,表明客戶端希望接受GIF圖象格式的資源;Accept:text/html,表明客戶端希望接受html文本。
Accept-Charset
Accept-Charset請求報頭域用于指定客戶端接受的字符集。eg:Accept-Charset:iso-8859-1,gb2312.如果在請求消息中沒有設置這個域,缺省是任何字符集都可以接受。
Accept-Encoding
Accept-Encoding請求報頭域類似于Accept,但是它是用于指定可接受的內容編碼。eg:Accept-Encoding:gzip.deflate.如果請求消息中沒有設置這個域服務器假定客戶端對各種內容編碼都可以接受。
Accept-Language
Accept-Language請求報頭域類似于Accept,但是它是用于指定一種自然語言。eg:Accept-Language:zh-cn.如果請求消息中沒有設置這個報頭域,服務器假定客戶端對各種語言都可以接受。
Authorization
Authorization請求報頭域主要用于證明客戶端有權查看某個資源。當瀏覽器訪問一個頁面時,如果收到服務器的響應代碼為401(未授權),可以發送一個包含Authorization請求報頭域的請求,要求服務器對其進行驗證。
Host(發送請求時,該報頭域是必需的)
Host請求報頭域主要用于指定被請求資源的Internet主機和端口號,它通常從HTTP URL中提取出來的,eg:
我們在瀏覽器中輸入:http://www.guet.edu.cn/index.html
瀏覽器發送的請求消息中,就會包含Host請求報頭域,如下:
Host:www.guet.edu.cn
此處使用缺省端口號80,若指定了端口號,則變成:Host:www.guet.edu.cn:指定端口號
User-Agent
我們上網登陸論壇的時候,往往會看到一些歡迎信息,其中列出了你的操作系統的名稱和版本,你所使用的瀏覽器的名稱和版本,這往往讓很多人感到很神奇,實際上,服務器應用程序就是從User-Agent這個請求報頭域中獲取到這些信息。User-Agent請求報頭域允許客戶端將它的操作系統、瀏覽器和其它屬性告訴服務器。不過,這個報頭域不是必需的,如果我們自己編寫一個瀏覽器,不使用User-Agent請求報頭域,那么服務器端就無法得知我們的信息了。
具體例子見下面測試
③HTTP協議詳解之響應篇
在接收和解釋請求消息后,服務器返回一個HTTP響應消息。
HTTP響應也是由三個部分組成,分別是:狀態行、消息報頭、響應正文(即實體報頭+實體正文)
1.狀態行格式如下:
HTTP-Version Status-Code Reason-Phrase CRLF
Status-Code表示服務器發回的響應狀態代碼;
Reason-Phrase表示狀態代碼的文本描述。
CRLF:除實體主體外所有協議元素的行結束標志。CR回車\r,LF換行\n
比如
HTTP/1.0 200 OK\r\n
2..消息報頭(響應報頭)在httpd.h中定義
#define STD_HEADER "Connection: close\r\n" \
?????????????????? "Server: MJPG-Streamer/0.2\r\n" \
?????????????????? "Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0\r\n" \
?????????????????? "Pragma: no-cache\r\n" \
?????????????????? "Expires: Mon, 3 Jan 2000 12:34:56 GMT\r\n"
3.實體報頭即mimetype
用于向瀏覽器說明實體正文的類型
?比如"Content-type: image/jpeg\r\n" \
實體正文
比如jpg格式的圖像數據
看一下httpd.c在響應瀏覽器請求時,發送了怎樣的狀態行 消息報頭 實體報頭.
先貼出 STD_HEADER
httpd.h
#define STD_HEADER "Connection: close\r\n" \"Server: MJPG-Streamer/0.2\r\n" \"Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0\r\n" \"Pragma: no-cache\r\n" \"Expires: Mon, 3 Jan 2000 12:34:56 GMT\r\n"
1.case A_SNAPSHOT:
/****************************************************************************** Description.: Send a complete HTTP response and a single JPG-frame. Input Value.: fildescriptor fd to send the answer to Return Value: - ******************************************************************************/ void send_snapshot(int fd) {unsigned char *frame=NULL;int frame_size=0;char buffer[BUFFER_SIZE] = {0};/* wait for a fresh frame */pthread_cond_wait(&pglobal->db_update, &pglobal->db);/* read buffer */frame_size = pglobal->size;/* allocate a buffer for this single frame */if ( (frame = malloc(frame_size+1)) == NULL ) {free(frame);pthread_mutex_unlock( &pglobal->db );send_error(fd, 500, "not enough memory");return;}memcpy(frame, pglobal->buf, frame_size);DBG("got frame (size: %d kB)\n", frame_size/1024);pthread_mutex_unlock( &pglobal->db );/* write the response */sprintf(buffer, "HTTP/1.0 200 OK\r\n" \ //狀態行STD_HEADER \ //響應報頭"Content-type: image/jpeg\r\n" \ //實體報頭,圖像"\r\n");/* send header and image now */if( write(fd, buffer, strlen(buffer)) < 0 || \write(fd, frame, frame_size) < 0) { //實體正文free(frame);return;}free(frame); } 2.case A_STREAM:
/****************************************************************************** Description.: Send a complete HTTP response and a stream of JPG-frames. Input Value.: fildescriptor fd to send the answer to Return Value: - ******************************************************************************/ void send_stream(int fd) {unsigned char *frame=NULL, *tmp=NULL;int frame_size=0, max_frame_size=0;char buffer[BUFFER_SIZE] = {0};DBG("preparing header\n");sprintf(buffer, "HTTP/1.0 200 OK\r\n" \ //狀態行STD_HEADER \ //響應報頭"Content-Type: multipart/x-mixed-replace;boundary=" BOUNDARY "\r\n" \ //實體報頭,后續還有"\r\n" \"--" BOUNDARY "\r\n");if ( write(fd, buffer, strlen(buffer)) < 0 ) {free(frame);return;}DBG("Headers send, sending stream now\n");while ( !pglobal->stop ) {/* wait for fresh frames */pthread_cond_wait(&pglobal->db_update, &pglobal->db);/* read buffer */frame_size = pglobal->size;/* check if framebuffer is large enough, increase it if necessary */if ( frame_size > max_frame_size ) {DBG("increasing buffer size to %d\n", frame_size);max_frame_size = frame_size+TEN_K;if ( (tmp = realloc(frame, max_frame_size)) == NULL ) {free(frame);pthread_mutex_unlock( &pglobal->db );send_error(fd, 500, "not enough memory");return;}frame = tmp;}memcpy(frame, pglobal->buf, frame_size);DBG("got frame (size: %d kB)\n", frame_size/1024);pthread_mutex_unlock( &pglobal->db );/** print the individual mimetype and the length* sending the content-length fixes random stream disruption observed* with firefox*/sprintf(buffer, "Content-Type: image/jpeg\r\n" \"Content-Length: %d\r\n" \"\r\n", frame_size); //實體報頭DBG("sending intemdiate header\n");if ( write(fd, buffer, strlen(buffer)) < 0 ) break;DBG("sending frame\n");if( write(fd, frame, frame_size) < 0 ) break; //實體正文DBG("sending boundary\n");sprintf(buffer, "\r\n--" BOUNDARY "\r\n");if ( write(fd, buffer, strlen(buffer)) < 0 ) break;}free(frame); }3.case A_FILE:
/****************************************************************************** Description.: Send HTTP header and copy the content of a file. To keep thingssimple, just a single folder gets searched for the file. Justfiles with known extension and supported mimetype get served.If no parameter was given, the file "index.html" will be copied. Input Value.: * fd.......: filedescriptor to send data to* parameter: string that consists of the filename* id.......: specifies which server-context is the right one Return Value: - ******************************************************************************/ void send_file(int id, int fd, char *parameter) {char buffer[BUFFER_SIZE] = {0};char *extension, *mimetype=NULL;int i, lfd;config conf = servers[id].conf;/* in case no parameter was given */if ( parameter == NULL || strlen(parameter) == 0 )parameter = "index.html";/* find file-extension */if ( (extension = strstr(parameter, ".")) == NULL ) {send_error(fd, 400, "No file extension found");return;}/* determine mime-type */for ( i=0; i < LENGTH_OF(mimetypes); i++ ) {if ( strcmp(mimetypes[i].dot_extension, extension) == 0 ) { /* mimetypes定義在httpd.h,過濾文件的后擴展名 static const struct {const char *dot_extension;const char *mimetype; } mimetypes[] = {{ ".html", "text/html" },{ ".htm",? "text/html" },{ ".css",? "text/css" },{ ".js",?? "text/javascript" },{ ".txt",? "text/plain" },{ ".jpg",? "image/jpeg" },{ ".jpeg", "image/jpeg" },{ ".png",? "image/png"},{ ".gif",? "image/gif" },{ ".ico",? "image/x-icon" },{ ".swf",? "application/x-shockwave-flash" },{ ".cab",? "application/x-shockwave-flash" },{ ".jar",? "application/java-archive" } }; 所以按照這個mimetypes,客戶瀏覽器訪問 http://192.168.1.230:8080/test.cgi 時,服務器就會返回下面的404錯誤 如果加上下面一行,使支持cgi { ".cgi", "magnus-internal/cgi" },但實驗中,瀏覽器直接彈出一個保存對話框。。。原因待查。。。 如果是{ ".cgi", "text/html" },輸出是亂碼使支持瀏覽器在線打開pdf { ".pdf", "application/pdf" },可以。 各個mimetype(content-type) http://blog.csdn.net/fanweiwei/article/details/1787747 */mimetype = (char *)mimetypes[i].mimetype;break;}}/* in case of unknown mimetype or extension leave */if ( mimetype == NULL ) {send_error(fd, 404, "MIME-TYPE not known");return;}/* now filename, mimetype and extension are known */DBG("trying to serve file \"%s\", extension: \"%s\" mime: \"%s\"\n", parameter, extension, mimetype);/* build the absolute path to the file */strncat(buffer, conf.www_folder, sizeof(buffer)-1);strncat(buffer, parameter, sizeof(buffer)-strlen(buffer)-1);/* try to open that file */if ( (lfd = open(buffer, O_RDONLY)) < 0 ) {DBG("file %s not accessible\n", buffer);send_error(fd, 404, "Could not open file");return;}DBG("opened file: %s\n", buffer);/* prepare HTTP header */sprintf(buffer, "HTTP/1.0 200 OK\r\n" \ //狀態行"Content-type: %s\r\n" \STD_HEADER \ //響應報頭"\r\n", mimetype); //實體報頭。可將"Content-type: %s\r\n" 放在STD_HEADER后面。i = strlen(buffer);/* first transmit HTTP-header, afterwards transmit content of file */do {if ( write(fd, buffer, i) < 0 ) { //實體正文close(lfd);return;}} while ( (i=read(lfd, buffer, sizeof(buffer))) > 0 );/* close file, job done */close(lfd); }
以下是 在firefox瀏覽器中輸入
http://192.168.1.230:8080/?action=snapshot
之后抓取的所有相關的包,192.168.1.101(client)<-->192.168.1.230(webserver)
圖1
有兩個關鍵的tcp報文--協議是http的
NO 6和NO 21
NO 6就是對應瀏覽器向webserver請求時發送的數據,包括請求行和請求報頭,共計401字節,具體如下
圖2
NO 21對應webserver返回的數據的一部分,72字節。和其他9個tcp報文共同組成一個http報文。即圖1黑的底色的標記的部分,共計10個tcp報文。
為什么要將一個http的數據分開?又為什么要分成10個?
因為數據鏈路層的以太網幀的數據部分最大是1500字節,然后再加上14個字節的以太網頭部---所以是1514字節--和圖1的NO9 11 12 14 15 17 18 20幀的長度對應。
所以在webserver上的http層將數據交給tcp再給ip再給數據鏈路層時,會將ip層下來的數據分片,每片最大1500+14字節。所以分成了若干個。
然后在客戶端接收時,在ip層會將分片的其組裝起來然后再交給http層。
圖3
其實仔細看一下可以知道,狀態行和響應報頭的數據是在NO 8里面的
圖4
NO9 11 12 14 15 17 18 20 21對應實體正文,即圖像數據
看一下圖像數據,
NO 9
0000 00 22 fa 7b 9b 76 08 90 90 90 90 90 08 00 45 00 .".{.v.. ......E. 0010 05 dc 9d c2 40 00 40 06 12 be c0 a8 01 e6 c0 a8 ....@.@. ........ 0020 01 65 1f 90 05 d7 4b f6 31 0b 3a a2 68 46 50 10 .e....K. 1.:.hFP. 0030 19 20 17 85 00 00 ff d8 ff db 00 84 00 10 0b 0c . ...... ........ 0040 0e 0c 0a 10 0e 0d 0e 12 11 10 13 18 28 1a 18 16 ........ ....(... 0050 16 18 31 23 25 1d 28 3a 33 3d 3c 39 33 38 37 40 ..1#%.(: 3=<9387@ 0060 48 5c 4e 40 44 57 45 37 38 50 6d 51 57 5f 62 67 H\N@DWE7 8PmQW_bg 0070 68 67 3e 4d 71 79 70 64 78 5c 65 67 63 01 11 12 hg>Mqypd x\egc... 0080 12 18 15 18 2f 1a 1a 2f 63 42 38 42 63 63 63 63 ..../../ cB8Bcccc 0090 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 cccccccc cccccccc 00a0 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 cccccccc cccccccc 00b0 63 63 63 63 63 63 63 63 63 63 63 63 63 63 ff c4 cccccccc cccccc.. 00c0 01 a2 00 00 01 05 01 01 01 01 01 01 00 00 00 00 ........ ........ 00d0 00 00 00 00 01 02 03 04 05 06 07 08 09 0a 0b 01 ........ ........ 00e0 00 03 01 01 01 01 01 01 01 01 01 00 00 00 00 00 ........ ........ 00f0 00 01 02 03 04 05 06 07 08 09 0a 0b 10 00 02 01 ........ ........ 0100 03 03 02 04 03 05 05 04 04 00 00 01 7d 01 02 03 ........ ....}... 0110 00 04 11 05 12 21 31 41 06 13 51 61 07 22 71 14 .....!1A ..Qa."q. 0120 32 81 91 a1 08 23 42 b1 c1 15 52 d1 f0 24 33 62 2....#B. ..R..$3b 0130 72 82 09 0a 16 17 18 19 1a 25 26 27 28 29 2a 34 r....... .%&'()*4 0140 35 36 37 38 39 3a 43 44 45 46 47 48 49 4a 53 54 56789:CD EFGHIJST 0150 55 56 57 58 59 5a 63 64 65 66 67 68 69 6a 73 74 UVWXYZcd efghijst 0160 75 76 77 78 79 7a 83 84 85 86 87 88 89 8a 92 93 uvwxyz.. ........ 0170 94 95 96 97 98 99 9a a2 a3 a4 a5 a6 a7 a8 a9 aa ........ ........ 0180 b2 b3 b4 b5 b6 b7 b8 b9 ba c2 c3 c4 c5 c6 c7 c8 ........ ........ 0190 c9 ca d2 d3 d4 d5 d6 d7 d8 d9 da e1 e2 e3 e4 e5 ........ ........ 01a0 e6 e7 e8 e9 ea f1 f2 f3 f4 f5 f6 f7 f8 f9 fa 11 ........ ........ 01b0 00 02 01 02 04 04 03 04 07 05 04 04 00 01 02 77 ........ .......w 01c0 00 01 02 03 11 04 05 21 31 06 12 41 51 07 61 71 .......! 1..AQ.aq 01d0 13 22 32 81 08 14 42 91 a1 b1 c1 09 23 33 52 f0 ."2...B. ....#3R. 01e0 15 62 72 d1 0a 16 24 34 e1 25 f1 17 18 19 1a 26 .br...$4 .%.....& 01f0 27 28 29 2a 35 36 37 38 39 3a 43 44 45 46 47 48 '()*5678 9:CDEFGH 0200 49 4a 53 54 55 56 57 58 59 5a 63 64 65 66 67 68 IJSTUVWX YZcdefgh 0210 69 6a 73 74 75 76 77 78 79 7a 82 83 84 85 86 87 ijstuvwx yz...... 0220 88 89 8a 92 93 94 95 96 97 98 99 9a a2 a3 a4 a5 ........ ........ 0230 a6 a7 a8 a9 aa b2 b3 b4 b5 b6 b7 b8 b9 ba c2 c3 ........ ........ 0240 c4 c5 c6 c7 c8 c9 ca d2 d3 d4 d5 d6 d7 d8 d9 da ........ ........ 0250 e2 e3 e4 e5 e6 e7 e8 e9 ea f2 f3 f4 f5 f6 f7 f8 ........ ........ 0260 f9 fa ff c0 00 11 08 01 e0 02 80 03 01 21 00 02 ........ .....!.. 0270 11 01 03 11 01 ff da 00 0c 03 01 00 02 11 03 11 ........ ........ 0280 00 3f 00 ea 68 c5 59 21 40 a0 02 96 80 0c 50 05 .?..h.Y! @.....P. 0290 20 16 8c 50 02 62 8c 50 30 c5 18 a0 05 02 8c 52 ..P.b.P 0......R 02a0 10 b8 a4 c5 00 18 a7 0a 60 38 52 8a 43 16 8c 50 ........ `8R.C..P 02b0 03 94 52 95 a0 06 11 8a 50 73 54 88 68 8a 58 f2 ..R..... PsT.h.X. 02c0 2a b0 8b 0f 44 b4 08 32 f4 23 0a 2a 4c 54 22 c5 *...D..2 .#.*LT". 02d0 03 8a 4c 53 18 1a 41 40 87 01 52 0a 06 2e 28 a4 ..LS..A@ ..R...(. 02e0 01 45 30 0a 28 01 28 a4 02 1a 43 40 0d e9 48 68 .E0.(.(. ..C@..Hh 02f0 01 a6 b3 dc 6d ba 7f f6 b9 a0 68 92 90 d2 00 c5 ....m... ..h..... 0300 34 50 02 9a 70 1c 53 10 50 45 00 03 8a 0f 5a 04 4P..p.S. PE....Z. 0310 14 62 80 00 29 d8 a6 21 08 a6 1a 43 0a 5a 60 25 .b..)..! ...C.Z`% 0320 25 00 14 b8 a4 31 0d 36 80 15 69 d8 a0 03 14 86 %....1.6 ..i..... 0330 81 12 d1 56 21 3a d2 d0 08 4a 29 00 e0 29 68 01 ...V!:.. .J)..)h. 0340 28 a0 62 d0 28 10 62 8a 06 18 a5 a4 01 8a 31 40 (.b.(.b. ......1@ 0350 06 29 45 00 38 0a 5a 00 5a 28 01 ea 29 d4 00 15 .)E.8.Z. Z(..)... 0360 cd 44 57 14 5c 2c 2e 32 39 a6 f9 5c d3 93 ba 12 .DW.\,.2 9..\.... 0370 56 64 c8 b8 a7 62 a5 6c 50 a0 52 1a 60 34 8a 40 Vd...b.l P.R.`4.@ 0380 28 01 c2 9c 0e 28 01 c2 8a 00 29 69 00 94 53 00 (....(.. ..)i..S. 0390 a4 34 00 94 94 80 6b 52 01 40 08 45 50 bc 1b 66 .4....kR .@.EP..f 03a0 8d bd 4e 28 1a 1c 39 14 94 80 0d 20 a0 02 9c 3a ..N(..9. ... ...: 03b0 53 10 52 f6 a0 42 51 40 05 2d 30 0a 70 a0 04 35 S.R..BQ@ .-0.p..5 03c0 19 34 02 01 4b 40 08 68 a0 00 52 d2 01 29 b4 0c .4..K@.h ..R..).. 03d0 05 3c 50 02 d3 4d 02 1e 29 6a c4 2e 29 29 00 50 .<P..M.. )j..)).P 03e0 28 b0 0b 4b 40 05 14 00 b4 50 30 a5 c5 20 0a 31 (..K@... .P0.. .1 03f0 40 0b 46 28 01 71 48 28 01 c2 94 0a 00 5c 52 81 @.F(.qH( .....\R. 0400 40 0e 02 9d 8a 06 28 a3 14 00 9b 69 71 4a c0 14 @.....(. ...iqJ.. 0410 b4 c0 5a 42 28 01 29 28 00 a7 0a 00 70 a5 a4 02 ..ZB(.)( ....p... 0420 52 d3 01 05 14 80 29 bd e9 80 b4 86 90 0c 34 50 R.....). ......4P 0430 00 6a 96 a0 bf bb 0d dd 48 a0 68 62 f4 a5 a4 02 .j...... H.hb.... 0440 52 0e 28 01 69 45 31 08 69 45 08 02 96 84 21 28 R.(.iE1. iE....!( 0450 14 00 ea 05 30 11 aa 33 48 10 ab 4a 69 80 94 94 ....0..3 H..Ji... 0460 80 51 4a 28 01 0d 14 00 94 e1 40 0b 4d 34 00 f1 .QJ(.... ..@.M4.. 0470 4b 9a b6 20 cd 14 80 29 45 00 14 a2 81 8b 8a 28 K.. ...) E......( 0480 10 52 8a 43 17 14 62 80 16 93 14 00 b8 a5 02 80 .R.C..b. ........ 0490 16 9a c3 14 20 14 53 85 00 3a 94 50 03 85 38 0a .... .S. .:.P..8. 04a0 06 18 a2 80 14 51 8a 00 31 4b 48 02 8c 50 03 68 .....Q.. 1KH..P.h 04b0 c5 30 0c 52 e2 90 0a 29 68 00 a4 ed 4c 02 96 90 .0.R...) h...L... 04c0 08 68 a0 04 a4 34 00 c6 1c 52 01 40 c4 39 a8 2e .h...4.. .R.@.9.. 04d0 13 74 4c 3d a9 02 2b 42 72 8a 7d aa 43 40 0d a2 .tL=..+B r.}.C@.. 04e0 80 16 80 79 a6 21 69 28 00 a5 ed 40 09 4b 40 85 ...y.!i( ...@.K@. 04f0 a2 80 10 f4 a6 62 80 42 8a 29 80 94 94 80 51 4b .....b.B .)....QK 0500 40 01 a4 a0 04 a5 14 0c 75 34 d0 21 e2 96 ac 41 @....... u4.!...A 0510 45 20 16 8a 00 50 28 e9 40 0b 40 a4 31 68 a0 05 E ...P(. @.@.1h.. 0520 14 b4 00 b4 94 00 a2 96 80 0a 08 e2 80 11 69 e2 ........ ......i. 0530 81 8e 02 8a 00 70 a7 0a 00 5a 28 00 14 b4 00 51 .....p.. .Z(....Q 0540 48 02 8a 60 21 a4 c5 00 2d 14 00 b4 b4 00 52 50 H..`!... -.....RP 0550 02 d1 40 09 45 20 12 90 d0 31 29 28 01 2a 29 46 ..@.E .. .1)(.*)F 0560 54 8a 4c 0a 10 f1 95 f4 38 a9 73 40 30 a4 c5 00 T.L..... 8.s@0... 0570 2f 6a 28 10 50 29 80 b4 94 00 82 9e 28 10 51 da /j(.P).. ....(.Q. 0580 98 05 30 d2 01 05 2d 30 12 8a 00 51 45 00 21 a4 ..0...-0 ...QE.!. 0590 a4 30 a5 14 00 b4 50 21 e3 a5 21 aa 10 50 29 80 .0....P! ..!..P). 05a0 ea 29 00 52 e2 80 17 14 bd a9 0c 05 28 a0 00 52 .).R.... ....(..R 05b0 d0 02 d1 40 0b 4a 28 18 b4 98 a0 43 71 83 52 2d ...@.J(. ...Cq.R- 05c0 0c 07 52 e3 34 0c 50 29 69 00 b4 53 01 69 28 01 ..R.4.P) i..S.i(. 05d0 68 a4 01 45 00 14 62 98 09 8a 5a 00 29 69 00 52 h..E..b. ..Z.)i.R 05e0 62 80 16 8a 00 4a 43 40 00 14 b....JC@ .. NO 10
0000 00 22 fa 7b 9b 76 08 90 90 90 90 90 08 00 45 00 .".{.v.. ......E. 0010 05 dc 9d c3 40 00 40 06 12 bd c0 a8 01 e6 c0 a8 ....@.@. ........ 0020 01 65 1f 90 05 d7 4b f6 36 bf 3a a2 68 46 50 10 .e....K. 6.:.hFP. 0030 19 20 7e cc 00 00 94 00 1a 61 a0 04 a6 b0 c8 e6 . ~..... .a...... 0040 90 cc f3 c5 cb 8e c7 91 52 52 01 0d 2d 31 00 a2 ........ RR..-1.. 0050 80 10 d2 8e 69 80 b4 62 80 13 1c d3 a8 42 12 81 ....i..b .....B.. 0060 40 05 21 a0 06 d1 40 c2 8a 62 01 4b 48 02 8a 06 @.!...@. .b.KH... 0070 25 14 08 5a 43 d2 80 1d 4a 2a c4 2e 28 a4 00 29 %..ZC... J*..(..) 0080 68 18 b4 b4 08 5a 28 18 52 d2 00 14 e1 40 21 68 h....Z(. R....@!h 0090 a0 05 a6 96 c5 08 18 6f a7 83 9a 01 01 14 ab d2 .......o ........ 00a0 81 8e 14 e1 40 0b 4b 40 05 14 00 a2 8a 40 14 50 ....@.K@ .....@.P 00b0 00 29 68 01 29 68 00 a4 a0 05 a4 a0 05 a2 80 13 .)h.)h.. ........ 00c0 34 50 01 45 00 34 b6 29 68 01 a6 98 68 00 a6 13 4P.E.4.) h...h... 00d0 48 65 19 c6 db a5 3e a2 9f d4 52 e8 02 76 a0 1a He....>. ..R..v.. 00e0 60 03 ad 19 a1 00 a6 81 c5 02 16 81 4c 00 d2 66 `....... ....L..f 00f0 80 0a 5a 04 2d 25 30 1b 45 00 04 52 50 02 0a 75 ..Z.-%0. E..RP..u 0100 20 0a 28 00 a2 80 0a 0d 00 3a 8a a1 0a 28 c5 00 .(..... .:...(.. 0110 14 a2 81 8e a0 52 10 52 d0 30 a5 14 00 b4 a2 80 .....R.R .0...... 0120 14 52 d0 30 c5 31 93 34 08 55 5a 78 14 90 c5 ed .R.0.1.4 .UZx.... 0130 48 bc 53 01 c2 9c 29 00 a2 8a 60 3a 81 40 05 28 H.S...). ..`:.@.( 0140 a4 01 45 00 14 b4 00 94 b4 00 52 01 40 06 29 45 ..E..... ..R.@.)E 0150 00 14 50 02 62 90 f4 e2 80 11 72 07 27 34 a6 98 ..P.b... ..r.'4.. 0160 09 91 45 20 03 4c 26 80 12 98 69 01 4e f0 60 a3 ..E .L&. ..i.N.`. 0170 7a 1c 52 0e 94 ba 14 2f 6a 05 31 05 14 00 b4 50 z.R..../ j.1....P 0180 21 45 28 a6 02 1a 6e 28 01 45 14 00 ea 29 92 34 !E(...n( .E...).4 0190 d2 50 30 a4 34 02 10 53 85 21 b1 69 28 b0 84 a5 .P0.4..S .!.i(... 01a0 14 00 b4 1a 00 5a 2a 84 14 a2 80 0a 5a 43 16 96 .....Z*. ....ZC.. 01b0 80 0a 28 01 69 45 00 2d 2d 20 14 52 d3 18 b4 50 ..(.iE.- - .R...P 01c0 21 68 a0 62 8a 46 14 00 a2 9e 29 00 a0 52 e2 98 !h.b.F.. ..)..R.. 01d0 06 28 a0 05 a3 a5 20 16 8a 00 28 a0 02 8a 00 28 .(.... . ..(....( 01e0 a0 02 92 98 0b 45 00 25 18 a0 04 c5 06 90 09 40 .....E.% .......@ 01f0 a0 00 f4 a6 91 40 c6 9a 6e 29 01 5e f5 37 40 71 .....@.. n).^.7@q 0200 db 9a 89 7a 52 0e 81 4a 29 80 98 a2 80 17 a0 a4 ...zR..J )....... 0210 cd 31 0e 06 96 81 01 a6 50 31 69 45 02 14 51 4c .1...... P1iE..QL 0220 18 da 29 00 86 9b 40 00 a7 0a 01 8b 49 40 09 4a ..)...@. ....I@.J 0230 28 01 d4 86 98 0a 0d 14 c4 14 0a 06 38 51 40 05 (....... ....8Q@. 0240 3a 90 05 14 00 b4 ec 50 01 4a 28 18 b4 a2 81 0b :......P .J(..... 0250 4b 40 05 14 0c 5a 0f 4a 10 81 4f 6a 78 a0 62 d2 K@...Z.J ..Ojx.b. 0260 8a 00 28 a0 05 14 52 00 a2 80 0a 05 00 2d 14 00 ..(...R. .....-.. 0270 51 40 05 14 00 51 40 05 21 a0 02 90 d0 02 66 8a Q@...Q@. !.....f. 0280 06 25 34 d2 01 29 0d 00 47 30 0d 0b 0a a7 11 f9 .%4..).. G0...... 0290 07 d2 90 0e cd 14 c0 5a 4a 04 2f 6a 6d 00 28 a7 .......Z J./jm.(. 02a0 8a 60 06 9a 68 01 45 14 08 5a 28 01 28 a6 02 1a .`..h.E. .Z(.(... 02b0 69 14 00 01 4a 29 00 b4 86 80 12 94 50 03 a9 0d i...J).. ....P... 02c0 00 02 96 a8 41 4b 40 c3 34 a2 80 0c 52 8a 40 2d ....AK@. 4...R.@- 02d0 14 00 a2 9c 28 01 69 68 18 b4 50 21 45 14 0c 5a ....(.ih ..P!E..Z 02e0 51 40 0b 46 28 01 ac 31 cd 28 34 00 f1 4a 29 00 Q@.F(..1 .(4..J). 02f0 b4 b9 a6 01 4b 40 09 45 20 0a 05 30 16 8a 40 14 ....K@.E ..0..@. 0300 94 00 52 d0 02 51 40 05 25 00 14 1a 06 25 21 3e ..R..Q@. %....%!> 0310 94 08 4a 31 40 c6 e6 9a 79 a4 02 11 f2 e2 a8 20 ..J1@... y...... 0320 c1 61 e8 4d 01 d0 93 b5 20 a1 00 b4 94 08 51 49 .a.M.... .....QI 0330 40 00 e9 4e 5a 62 1c 7a 54 7d e8 18 e1 4b 40 85 @..NZb.z T}...K@. 0340 14 94 c1 09 45 02 12 92 90 c1 69 68 00 a6 9a 01 ....E... ..ih.... 0350 09 4e 14 0c 5a 43 40 85 a2 a8 48 5a 5a 06 14 b4 .N..ZC@. ..HZZ... 0360 00 b4 52 01 45 27 7a 00 78 a5 14 00 b4 a2 80 16 ..R.E'z. x....... 0370 81 40 c5 a5 14 08 5a 28 18 b4 b4 00 84 71 48 94 .@....Z( .....qH. 0380 00 f0 69 d4 00 98 a5 c5 00 28 a2 80 0a 31 48 02 ..i..... .(...1H. 0390 81 40 0b 45 00 25 19 f4 a0 00 0a 28 00 a0 50 00 .@.E.%.. ...(..P. 03a0 69 bd e8 00 a3 34 0c 29 09 a0 43 72 29 09 34 00 i....4.) ..Cr).4. 03b0 d0 32 69 c1 69 0c 43 54 24 c2 ce e3 b9 39 a0 05 .2i.i.CT $....9.. 03c0 1d 28 a0 03 b5 14 00 0a 0d 02 01 d2 95 4d 30 63 .(...... .....M0c 03d0 fa 8a 66 28 b8 85 51 4a 68 00 14 50 02 51 40 08 ..f(..QJ h..P.Q@. 03e0 45 14 00 0a 5a 00 43 4d 34 00 82 9c 29 a0 16 9a E...Z.CM 4...)... 03f0 4d 20 16 8a a0 01 4e a0 05 14 b4 80 29 45 00 2d M ....N. ....)E.- 0400 2d 00 28 a5 a0 05 14 b4 00 a2 96 81 80 a7 62 80 -.(..... ......b. 0410 0c 52 d0 02 62 9c 29 00 53 0f 06 98 0f a5 14 00 .R..b.). S....... 0420 ea 28 00 a0 8a 00 00 a7 52 00 a4 a0 02 8a 00 42 .(...... R......B 0430 28 14 c0 75 26 69 00 51 40 09 48 45 00 14 0a 06 (..u&i.Q @.HE.... 0440 21 a6 31 39 a0 43 73 49 9a 00 95 17 8c 9a 18 d0 !.19.CsI ........ 0450 04 64 d5 0b 90 56 e5 5b fb c2 91 48 51 4b 9a 04 .d...V.[ ...HQK.. 0460 25 28 a0 18 b4 1e 28 10 0a 4a 00 92 9a 69 80 2f %(....(. .J...i./ 0470 4a 28 00 5a 5a 04 36 8a 00 51 45 30 12 96 80 12 J(.ZZ.6. .QE0.... 0480 9a 69 00 52 8a 60 2d 31 a9 00 ea 3b 55 00 52 83 .i.R.`-1 ...;U.R. 0490 40 0e 14 a2 90 05 28 a0 07 51 40 0a 29 68 01 45 @.....(. .Q@.)h.E 04a0 2d 00 2d 28 a0 61 4e cd 02 0c d2 d0 31 45 14 00 -.-(.aN. ....1E.. 04b0 53 58 71 40 0a 87 23 14 ea 40 28 e6 96 80 16 8a SXq@..#. .@(..... 04c0 60 26 69 41 a0 02 81 48 02 98 cd 8a 60 22 b6 4d `&iA...H ....`".M 04d0 48 3a 50 02 d1 48 06 96 e7 14 a2 80 0a 69 34 00 H:P..H.. .....i4. 04e0 94 66 80 03 4c a0 60 17 34 f5 40 39 34 20 06 3c .f..L.`. 4.@94 .< 04f0 71 4c 3d 28 01 b5 4e fb 84 56 ee 0d 20 43 07 4a qL=(..N. .V.. C.J 0500 51 cd 03 61 40 34 08 50 69 cd c8 a0 48 68 34 b4 Q..a@4.P i...Hh4. 0510 00 fc f1 4c 26 80 14 74 a2 98 85 02 8a 00 31 49 ...L&..t ......1I 0520 8a 2c 01 45 30 0a 4a 40 14 d3 40 09 4a 28 18 66 .,.E0.J@ ..@.J(.f 0530 90 d0 02 d0 2a 84 14 a3 8a 40 38 1a 5a 00 05 38 ....*... .@8.Z..8 0540 50 03 b3 45 00 28 a5 a0 05 a5 14 00 b4 b4 0c 29 P..E.(.. .......) 0550 45 02 16 96 81 85 2e 68 00 cd 14 00 c1 f2 bf b1 E......h ........ 0560 a9 48 a0 05 5e 94 b4 00 52 13 40 00 1c d2 d2 00 .H..^... R.@..... 0570 a4 a0 05 a6 95 cd 03 14 20 1d 29 45 00 14 99 a0 ........ .)E.... 0580 41 8c d0 28 01 6a 2c ee 27 1d a8 01 68 a0 02 9a A..(.j,. '...h... 0590 68 01 47 02 9e 4f 14 00 da 42 28 18 d2 2a b5 da h.G..O.. .B(..*.. 05a0 e6 16 1d e9 31 ad ca d1 9d c8 0f b5 38 71 40 0e ....1... ....8q@. 05b0 14 94 08 3a 1a 77 6a 04 20 14 a6 86 31 45 21 14 ...:.wj. ...1E!. 05c0 08 55 e9 4b 4c 40 3a d1 40 01 a0 50 02 52 50 00 .U.KL@:. @..P.RP. 05d0 29 68 01 0d 21 a0 06 d1 40 c2 83 40 85 a2 a8 05 )h..!... @..@.... 05e0 a6 39 c5 08 01 1e a6 07 8a 91 .9...... ..
下面是瀏覽器中輸入
http://192.168.1.230:8080/static.html
之后的相關http包
static.html 的源碼如下
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><title>MJPG-streamer</title><meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /><link rel="stylesheet" href="style.css" type="text/css" /><!--[if IE 6]><link rel="stylesheet" href="fix.css" type="text/css" /><![endif]--></head><body><div id="sidebar"><h1>MJPG-Streamer Demo Pages</h1><h2>a ressource friendly streaming application</h2><div id="menu"><a href="index.html">Home</a><a class="active" href="static.html">Static</a> <a href="stream.html">Stream</a> <a href="java.html">Java</a> <a href="javascript.html">Javascript</a><a href="videolan.html">VideoLAN</a><a target="_blank" onClick="window.open(this.href, '_blank','width=400,height=400'); return false;" href="control.htm">Control</a></div><h3>Version info:</h3><p>v0.1 (Okt 22, 2007)</p></div><div id="content"><h1>Static</h1><h2>A static snapshot</h2><h3>Hints</h3><p>This example shows a static snapshot. It should work with any browser. To see a simple example click <a href="static_simple.html">here</a>.</p><h3>Source snippet</h3><p><pre><img src="/?action=snapshot" /></pre></p><img src="/?action=snapshot" alt="This is a static snapshot" width="512px" height="384px" /><p>? The <a href="http://mjpg-streamer.sf.net">MJPG-streamer team</a> | Design by <a href="http://andreasviklund.com">Andreas Viklund</a></p></div></body> </html> 根據源碼和抓取的包中若干GET方法可以推斷整個過程:
1.瀏覽器首先根據地址欄里的/static.html,發送一個GET/static.html HTTP/1.1請求。然后服務器響應,將static,html發出
2.瀏覽器依次解釋static.html的html標記,以便將static.html的內容顯示出來。
3.解釋到line 7,會發送GET /style.css HTTP/1.1請求。以獲取style.css文件。
4.解釋到line 44,會發送GET /?action=snapshot請求,以獲取圖像數據。
轉載于:https://www.cnblogs.com/-song/archive/2011/11/27/3331921.html
總結
以上是生活随笔為你收集整理的---WebCam网络摄像头11 http协议的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ---WebCam网络摄像头10 soc
- 下一篇: 王菲 人间