一德挣、工具
(1) charles (抓包工具)
charles for mac 下載
(2) 美食杰 (數(shù)據(jù)來源)
AppStore搜索 美食杰
二、教程
1.打開charles
2.查看本機ip
3.在蘋果設(shè)備上設(shè)置代理
4.操作美食杰app查看charles抓取到數(shù)據(jù)
注意:電腦的網(wǎng)絡(luò)和移動設(shè)備的網(wǎng)路必須在同一網(wǎng)段里格嗅,設(shè)置完代理祸泪,charles會彈出是否允許訪問的對話框吗浩,點擊allow就可以了。
三没隘、效果
1.寫了個簡單的http請求
封裝的請求方法:
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; if ([aMethod isEqualToString:GET_METHOD]) { NSMutableString *urlString = [[NSMutableString alloc] initWithString:aURLString]; NSArray *paramArray = params.allKeys; for (NSString *tempString in paramArray) { int index = (int)[paramArray indexOfObject:tempString]; [urlString appendFormat:@"&%@=%@",tempString,params[tempString]]; } request.URL = [NSURL URLWithString:urlString]; }else if ([aMethod isEqualToString:POST_METHOD]){ //請求參數(shù) NSString *paramsJsonString = [self DataTOjsonString:params]; request.HTTPBody = [paramsJsonString dataUsingEncoding:NSUTF8StringEncoding]; request.URL = [NSURL URLWithString:aURLString]; } //請求方法 request.HTTPMethod = aMethod; [NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) { NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; aSuccess([self dictionaryWithJsonString:responseString]); }];
發(fā)送請求:
NSArray *sortAray = @[@"step",@"default",@"time"]; NSArray*tArray=@[@"zao",@"zhong",@"xiawucha",@"wan",@"yexiao"]; for (int a = 0; a<1000; a++) { NSMutableDictionary *params = [NSMutableDictionary dictionary]; [params setValue:@"" forKey:@"lat"]; [params setValue:@"" forKey:@"lon"]; [params setValue:@"iphone" forKey:@"source"]; [params setValue:sortAray[random()%sortAray.count] forKey:@"sort"]; [params setValue:tArray[random()%tArray.count] forKey:@"t"]; [params setValue:@"" forKey:@"kw"]; [params setValue:@"desc" forKey:@"sort_sc"]; [params setValue:@"" forKey:@"gy"]; [params setValue:@"" forKey:@"step"]; [params setValue:@"" forKey:@"mt"]; [params setValue:[NSString stringWithFormat:@"%d",a] forKey:@"page"]; [_msjNetwork api_get_candanWithUrl:@"http://api.meishi.cc/v5/class_list1.php?format=json" params:params successBlock:^(NSDictionary *responeDictionary) { } failBlock:^(NSError *error) { }]; }
響應(yīng):把得到的數(shù)據(jù)扎入本地數(shù)據(jù)庫
[self requestNetworkWithURLString:aUrl params:aParam requestMethod:GET_METHOD successBlock:^(NSDictionary *responeDictionary) { NSDictionary *temp1 = responeDictionary[@"obj"]; NSArray *temp2 = temp1[@"data"]; for (NSDictionary *temp3 in temp2) { NSString *msjID = temp3[@"id"]; MsjModel *temp = [MsjModel FindByID:msjID]; if (!temp) { temp = [[MsjModel alloc] init]; }else { continue; } temp.msjID = msjID; temp.gongyi = temp3[@"gongyi"]; temp.kouwei = temp3[@"kouwei"]; temp.mt = temp3[@"mt"]; temp.smalltext = temp3[@"smalltext"]; temp.titlepic = temp3[@"titlepic"]; temp.title = temp3[@"title"]; temp.md = temp3[@"md"]; [temp saveOrUpdateDB]; } asuccessBlock(responeDictionary); } failBlock:^(NSError *error) { }];
獲取到的數(shù)據(jù)
HTTP抓包
打開Charles程序
查看Mac電腦的IP地址,如192.168.1.7
打開iOS設(shè)置,進入當前wifi連接阀湿,設(shè)置HTTP代理Group赶熟,將服務(wù)器填為上一步中獲得的IP,即192.168.1.7陷嘴,端口填8888
iOS設(shè)備打開你要抓包的app進行網(wǎng)絡(luò)操作
Charles彈出確認框映砖,點擊Allow按鈕即可
HTTPS抓包
下載Charles證書http://www.charlesproxy.com/ssl.zip灾挨,解壓后導入到iOS設(shè)備中(將crt文件作為郵件附件發(fā)給自己邑退,再在iOS設(shè)備中點擊附件即可安裝;也可上傳至dropbox之類的網(wǎng)盤地技,通過safari下載安裝)
在Charles的工具欄上點擊設(shè)置按鈕秒拔,選擇Proxy Settings…
切換到SSL選項卡,選中Enable SSL Proxying作谚,別急妹懒,選完先別關(guān)掉,還有下一步
這 一步跟Fiddler不同喳挑,F(xiàn)iddler安裝證書后就可以抓HTTPS網(wǎng)址的包了彬伦,Charles則麻煩一些单绑,需要在上一步的SSL選項卡的 Locations表單填寫要抓包的域名和端口曹宴,點擊Add按鈕搂橙,在彈出的表單中Host填寫域名,比如填api.instagram.com笛坦,Port 填443
接下來就跟HTTP抓包一樣了
抓取微信的亂碼: