轉載:https://blog.csdn.net/jaryguo/article/details/53021923
轉載:https://www.cnblogs.com/miantest/p/7289694.html
轉載:https://www.cnblogs.com/joshua317/p/8670923.html
轉載:https://www.cnblogs.com/woaixuexi9999/p/9247705.html(Fiddler配置教程)
轉載:https://blog.csdn.net/u013908944/article/details/85076833(Fidler抓postman模擬請求的包)
轉載:https://www.cnblogs.com/TankXiao/archive/2013/01/08/2818542.html(HTTP協議 (六)狀態碼詳解)
轉載:https://blog.csdn.net/wangjun5159/article/details/54024413(fiddler 圖標解釋)
用libcurl在項目開發過程中,調試階段需要進行抓包測試,但Fiddler不能收到應用的Http連接。
Google了一下,因為應用用了libcurl的接口來創建HTTP連接,如果要使用Fiddler,需要在代碼中插入類似如下的代碼:
curl_easy_setopt(m_curl, CURLOPT_PROXY, "127.0.0.1:8888");
其中8888是Fiddler默認設置的一個監聽端口,如果在Option中修改了,則需要替換為響應的端口號。
代理就是在客戶端和服務器之間設置一道關卡,客戶端先將請求數據發送出去后,代理服務器會將數據包進行攔截,代理服務器再冒充客戶端發送數據到服務器;同理,服務器將響應數據返回,代理服務器也會將數據攔截,再返回給客戶端。
void Test() { CURL* curl; char *url = "http://develop.test.com"; std::stringstream out; curl = curl_easy_init(); //設置url curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_PROXY, "127.0.0.1:8888"); curl_easy_setopt(curl, CURLOPT_POST, 0);//設置為非0表示本次操作為POST // 設置接收數據的處理函數和存放變量 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);//設置回調函數 curl_easy_setopt(curl, CURLOPT_WRITEDATA, &out); // 執行HTTP GET操作 CURLcode res = curl_easy_perform(curl); if (res != CURLE_OK) { fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); } // 接受數據存放在out中,輸出之 //cout << out.str() << endl; string str_json = out.str(); printf("%s", str_json.c_str()); curl_easy_cleanup(curl); }
注:如果代碼中加入了設置代理,只有在抓包工具運行的情況下,http才能請求成功,進而能抓到數據;否則http會請求失敗;
WireShark則純粹是在底層監聽計算機的所有出入數據(需要安裝WinPCap),什么數據都能檢測到。
WireShark的使用教程:https://www.cnblogs.com/Jerry-zhao2110/p/8282427.html
二、Fiddler 抓取https請求配置
轉載:https://www.cnblogs.com/joshua317/p/8670923.html
1.清除C:\Users\Administrator\AppData\Roaming\Microsoft\Crypto\RSA 目錄下所有文件(首次安裝fiddler請忽略)
2.清除電腦上的根證書,WIN+R快捷鍵,輸入:certmgr.msc, 然后回車,查找所有fiddler證書,然后刪除。(首次安裝fiddler請忽略)
3.清除瀏覽器上的證書文件 ,此處需要仔細查找帶有FiddlerRoot的字樣,並刪除,以谷歌瀏覽器為例說明,在瀏覽器上輸入: chrome://settings/,(首次安裝fiddler請忽略)
4.打開fiddler,點擊工具欄中的Tools—>Options,點擊Actions,選擇最后一項,Reset All certificates,然后關閉
注意:以上步驟假設是已經安裝fiddler的情況下需要做的處理 ,若已安裝,建議執行上述步驟,然后進行重新安裝;
用Fiddler抓libcurl發起的https的包,需要在代碼中設置:
/* * If you want to connect to a site who isn't using a certificate that is * signed by one of the certs in the CA bundle you have, you can skip the * verification of the server's certificate. This makes the connection * A LOT LESS SECURE. * * If you have a CA cert for the server stored someplace else than in the * default bundle, then the CURLOPT_CAPATH option might come handy for * you. */ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
Fiddler中session前面快捷圖標的含義