2013-05-16 51 views
0

我有以下格式的原始HTTP流量文件:播放/運行捕獲HTTP流量文件

 
---------------------- dataset.txt ---------------------------------- 

GET http://localhost:8080/tienda1/index.jsp HTTP/1.1 
User-Agent: Mozilla/5.0 (compatible; Konqueror/3.5; Linux) KHTML/3.5.8 (like Gecko) 
Pragma: no-cache 
Cache-control: no-cache 
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 
Accept-Encoding: x-gzip, x-deflate, gzip, deflate 
Accept-Charset: utf-8, utf-8;q=0.5, *;q=0.5 
Accept-Language: en 
Host: localhost:8080 
Cookie: JSESSIONID=1F767F17239C9B670A39E9B10C3825F4 
Connection: close 

POST http://localhost:8080/tienda1/publico/anadir.jsp HTTP/1.1 
User-Agent: Mozilla/5.0 (compatible; Konqueror/3.5; Linux) KHTML/3.5.8 (like Gecko) 
Pragma: no-cache 
Cache-control: no-cache 
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 
Accept-Encoding: x-gzip, x-deflate, gzip, deflate 
Accept-Charset: utf-8, utf-8;q=0.5, *;q=0.5 
Accept-Language: en 
Host: localhost:8080 
Cookie: JSESSIONID=933185092E0B668B90676E0A2B0767AF 
Content-Type: application/x-www-form-urlencoded 
Connection: close 
Content-Length: 68 

id=3&nombre=Vino+Rioja&precio=100&cantidad=55&B1=A%F1adir+al+carrito 

... 
... 

是否有任何實用程序來讀取這個文件,並提交給我的本地Web服務器?

回答

0

這裏有兩個要求。 首先是GET,第二是POST。

只要你有如上述這樣的格式,可以編寫簡單的程序,將(按順序)

  1. 鴻溝片成獨立的HTTP請求
  2. 解析請求,並將它們分成等變量:請求類型(GET或POST),用戶代理和一般的「標題」,請求DATA,請求提交URL
  3. 創建並維護與特定服務器(cookie等)的會話
  4. 迭代循環並提交數據

這將是完美的解決python-requests的問題。解析可以在python的基本庫中完成。