NetworkUtils.m 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682
  1. //
  2. // NetworkUtils.m
  3. // AntsContract
  4. //
  5. // Created by Ray on 12/26/16.
  6. // Copyright © 2016 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "NetworkUtils.h"
  9. #import "RAUtils.h"
  10. #import "Reachability.h"
  11. #import "RANetworkTaskDelegate.h"
  12. #define BOUNDARY @"AaB03x"
  13. @implementation NetworkUtils
  14. //+(NSDictionary*) error_dict:(NSError*)error
  15. //{
  16. // if(error==nil)
  17. // return nil;
  18. // NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
  19. // [ret setValue:[NSString stringWithFormat:@"%d",error.code] forKey:@"error_code"];
  20. // [ret setValue:error.domain forKey:@"err_domain"];
  21. // [ret setValue:[error localizedDescription] forKey:@"err_message"];
  22. // // [ret setObject:error.userInfo forKey:@"user_info"];
  23. // return ret;
  24. //}
  25. +(bool) IsNetworkAvailable
  26. {
  27. if (([Reachability reachabilityForInternetConnection].currentReachabilityStatus == NotReachable) &&
  28. ([Reachability reachabilityForLocalWiFi].currentReachabilityStatus == NotReachable))
  29. return false;
  30. return true;
  31. }
  32. +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params file:(NSString*)file_path err_recorder:(NSString* )recorder_url result_handler:(resultBlock)resultBlock decrypt_handler:(decryptBlock)decryptBlock
  33. {
  34. int retry = 0;
  35. repeat:
  36. {
  37. // return [self fake_json:url];
  38. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  39. //分界线的标识符
  40. NSString *TWITTERFON_FORM_BOUNDARY = @"AaB03x";
  41. //根据url初始化request
  42. NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
  43. cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
  44. timeoutInterval:JSON_TIMEOUT];
  45. //分界线 --AaB03x
  46. NSString *MPboundary=[[NSString alloc]initWithFormat:@"--%@",TWITTERFON_FORM_BOUNDARY];
  47. //结束符 AaB03x--
  48. NSString *endMPboundary=[[NSString alloc]initWithFormat:@"%@--",MPboundary];
  49. //要上传的图片
  50. // UIImage *image=[params objectForKey:@"pic"];
  51. //得到图片的data
  52. NSData* data = [NSData dataWithContentsOfFile:file_path];
  53. //http body的字符串
  54. NSMutableString *body=[[NSMutableString alloc]init];
  55. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  56. // [params setValue:@"handset_login" forKey:@"action"];
  57. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  58. // [params setValue:appDelegate.sessionid forKey:@"sessionid"];
  59. // [params setValue:password forKey:@"password"];
  60. // [params setValue:[NSString stringWithFormat:@"%d",ver] forKey:@"auth_ver"];
  61. // [headers setValue:headQuerlString forKey:@"param"];
  62. //参数的集合的所有key的集合
  63. NSArray *keys= [params allKeys];
  64. DebugLog(@"================parms==================");
  65. //遍历keys
  66. for(int i=0;i<[keys count];i++)
  67. {
  68. //得到当前key
  69. NSString *key=[keys objectAtIndex:i];
  70. //如果key不是pic,说明value是字符类型,比如name:Boris
  71. if(![key isEqualToString:@"pic"])
  72. {
  73. //添加分界线,换行
  74. [body appendFormat:@"%@\r\n",MPboundary];
  75. //添加字段名称,换2行
  76. [body appendFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n",key];
  77. //添加字段的值
  78. [body appendFormat:@"%@\r\n",[params objectForKey:key]];
  79. DebugLog(@"parameter: key=%@ value=%@",key,[params objectForKey:key]);
  80. }
  81. }
  82. DebugLog(@"================parms==================");
  83. ////添加分界线,换行
  84. [body appendFormat:@"%@\r\n",MPboundary];
  85. //声明pic字段,文件名为boris.png
  86. NSString * file_format=[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"upfile\"; filename=\"%@\"\r\n", [file_path lastPathComponent]];
  87. [body appendFormat:@"%@", file_format];
  88. //声明上传文件的格式
  89. [body appendFormat:@"Content-Type: application/zip\r\n\r\n"];
  90. //声明结束符:--AaB03x--
  91. NSString *end=[[NSString alloc]initWithFormat:@"\r\n%@",endMPboundary];
  92. //声明myRequestData,用来放入http body
  93. NSMutableData *myRequestData=[NSMutableData data];
  94. //将body字符串转化为UTF8格式的二进制
  95. [myRequestData appendData:[body dataUsingEncoding:NSUTF8StringEncoding]];
  96. //将image的data加入
  97. [myRequestData appendData:data];
  98. //加入结束符--AaB03x--
  99. [myRequestData appendData:[end dataUsingEncoding:NSUTF8StringEncoding]];
  100. //设置HTTPHeader中Content-Type的值
  101. NSString *content=[[NSString alloc]initWithFormat:@"multipart/form-data; boundary=%@",TWITTERFON_FORM_BOUNDARY];
  102. //设置HTTPHeader
  103. [request setValue:content forHTTPHeaderField:@"Content-Type"];
  104. [request setValue:@"multipart/form-data" forHTTPHeaderField:@"enctype"];
  105. // 关闭keep alive
  106. [request setValue:@"close" forHTTPHeaderField:@"Connection"];
  107. //设置Content-Length
  108. [request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[myRequestData length]] forHTTPHeaderField:@"Content-Length"];
  109. //设置http body
  110. [request setHTTPBody:myRequestData];
  111. //http method
  112. [request setHTTPMethod:@"POST"];
  113. NSLog([[NSString alloc] initWithData:myRequestData encoding:NSUTF8StringEncoding]);
  114. NSHTTPURLResponse* urlResponse = nil;
  115. NSError *error = nil;
  116. NSLog(@"begin request %@",url);
  117. NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
  118. DebugLog(@"url: %@",url);
  119. DebugLog(@"response: %@",[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode]);
  120. NSLog(@"get response");
  121. if (responseData==nil) {
  122. // DebugLog(@"response error:%@", [error localizedDescription]);
  123. NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
  124. //#define RESULT_FALSE 0
  125. //#define RESULT_TRUE 2
  126. //#define RESULT_NET_ERROR -3
  127. //#define RESULT_NET_NOTAVAILABLE -4
  128. //#define RESULT_ERROR -5
  129. //#define RESULT_LOCALFILE_ERROR -7
  130. //#define RESULT_USERAUTH_ERROR -9
  131. //#define RESULT_UPDATE_USERAUTH_ERROR -11
  132. //#define RESULT_SESSION_EXPIRED -13
  133. //#define RESULT_VER_LOW
  134. // NSString * moreinfo = error.description ;
  135. NSString* err_msg = [error localizedDescription];
  136. //-----------------retry 3 times for error code -1005------------------------
  137. if(error.code==-1005&&retry<3)
  138. {
  139. retry++;
  140. goto repeat;
  141. }
  142. //-----------------end retry 3 times for error code -1005------------------------
  143. NSDictionary* error_json = [RAUtils error_dict:error];
  144. [ret setObject:error_json forKey:@"err_obj"];
  145. NSString* resp_msg= nil;
  146. if(err_msg.length==0)
  147. {
  148. err_msg =[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode];
  149. resp_msg = err_msg;
  150. }
  151. [ret setValue:[NSString stringWithFormat:@"%d",RESULT_NET_ERROR] forKey:@"result"];
  152. [ret setValue:err_msg forKey:@"err_msg"];
  153. [ret setValue:resp_msg forKey:@"resp_msg"];
  154. [ret setValue:[NSString stringWithFormat:@"%ld",(long)urlResponse.statusCode] forKey:@"resp_code"];
  155. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:ret
  156. options:0
  157. error:nil];
  158. if(![url isEqualToString:recorder_url])
  159. {
  160. [self err_log:[RAUtils base64en:[RAConvertor dict2string:params]] result:[RAUtils base64en:[RAConvertor dict2string:ret]] module:url code:RESULT_NET_ERROR];
  161. }
  162. return jsonData;
  163. }
  164. else
  165. {
  166. // NSString* err_msg = [error localizedDescription];
  167. NSMutableString *str = [[NSMutableString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
  168. DebugLog(@"data string: %@",str);
  169. NSError *error1 = nil;
  170. NSMutableDictionary* jsobj = [[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error1] mutableCopy];
  171. if(jsobj==nil)// 服务器返回不是json
  172. {
  173. jsobj=[[NSMutableDictionary alloc] init];
  174. [jsobj setValue:[NSNumber numberWithInt:RESULT_NO_RESPONSE] forKey:@"result"];
  175. }
  176. if([jsobj[@"encrypt"] boolValue]==true)
  177. {
  178. jsobj = decryptBlock(jsobj);
  179. }
  180. if (resultBlock) {
  181. jsobj = resultBlock(jsobj);
  182. }
  183. int result=[[jsobj valueForKey:@"result"] intValue];
  184. if(![url isEqualToString:recorder_url]&&/*![url isEqualToString:URL_DOWNLOAD_OFFLINE]&&*/result!=2&&result!=99)
  185. {
  186. [self err_log:[RAUtils base64en:[RAConvertor dict2string:params]] result:[RAUtils base64en:str] module:url code:result];
  187. }
  188. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsobj
  189. options:0
  190. error:nil];
  191. return jsonData;
  192. }
  193. return responseData;
  194. }
  195. }
  196. +(NSDictionary*)err_log:(NSString*) up_params result:(NSString*)result module:(NSString*) module code:(int) code//device:(NSString*) device
  197. {
  198. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  199. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  200. // if(appDelegate.user!=nil)
  201. // [params setValue:appDelegate.user forKey:@"user"];
  202. //
  203. // [params setValue:up_params forKey:@"upparam"];
  204. //
  205. // [params setValue:[NSNumber numberWithInt:code ] forKey:@"code"];
  206. //
  207. // [params setValue:result forKey:@"result"];
  208. // [params setValue:module forKey:@"interfac"];
  209. //
  210. // [params setValue:[RAUtils base64en:[RAUtils dict2string: [RAUtils device_info]]] forKey:@"device"];
  211. //
  212. //
  213. // // [params setValue:module forKey:@"module"];
  214. //
  215. // // [[UIDevice currentDevice] name];
  216. //
  217. // // if(appDelegate.offline_mode)
  218. // // {
  219. // // return [OLDataProvider offline_notimpl];
  220. // // }
  221. // if(![self IsNetworkAvailable])
  222. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  223. //
  224. // NSData* json=[self get_json:URL_ERR_LOG parameters:params];
  225. // if(json==nil)
  226. // return nil;
  227. // NSError *error=nil;
  228. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  229. // return jsobj;
  230. // 子类没有处理err_log函数时的默认处理。
  231. NSMutableDictionary* jsobj = [@{@"result":@"2"} mutableCopy];
  232. return jsobj;
  233. }
  234. + (NSURLSessionTask *)upload:(NSData *)filedata FileName:(NSString*) filename Params:(NSDictionary *)params ToHost:(NSString *)urlString Result:(resultHandler)r Progress:(progressHandler)p DecryptHandler:(id (^)(NSString *))decrypt {
  235. // NSString *fileName = [filePath lastPathComponent];
  236. NSMutableData *dataM = [NSMutableData data];
  237. NSMutableString *stringM = [NSMutableString string];
  238. DebugLog(@"================parms==================");
  239. for (NSString *key in params) {
  240. [stringM appendString:[NSString stringWithFormat:@"--%@\r\n",BOUNDARY]];
  241. [stringM appendFormat:@"Content-Type: text/plain; charset=UTF-8\r\n"];
  242. [stringM appendFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n",key];
  243. [stringM appendFormat:@"%@\r\n",[params objectForKey:key]];
  244. DebugLog(@"parameter: key=%@ value=%@",key,[params objectForKey:key]);
  245. }
  246. DebugLog(@"================parms==================");
  247. // Apex Drivers 2018.5.5
  248. if (filedata) {
  249. [stringM appendString:[NSString stringWithFormat:@"--%@\r\n",BOUNDARY]];
  250. [stringM appendFormat:@"Content-Disposition: form-data; name=\"upfile\"; filename=%@\r\n",filename];
  251. [stringM appendString:@"Content-Type: application/mac-binary\r\n"];
  252. [stringM appendString:@"\r\n"];
  253. NSData *stringM_data = [stringM dataUsingEncoding:NSUTF8StringEncoding];
  254. [dataM appendData:stringM_data];
  255. // NSData *file_data = [NSData dataWithContentsOfFile:filePath];
  256. [dataM appendData:filedata];
  257. NSString *end = [NSString stringWithFormat:@"\r\n--%@--",BOUNDARY];
  258. [dataM appendData:[end dataUsingEncoding:NSUTF8StringEncoding]];
  259. } else {
  260. NSData *stringM_data = [stringM dataUsingEncoding:NSUTF8StringEncoding];
  261. [dataM appendData:stringM_data];
  262. NSString *end = [NSString stringWithFormat:@"\r\n--%@--",BOUNDARY];
  263. [dataM appendData:[end dataUsingEncoding:NSUTF8StringEncoding]];
  264. }
  265. // Data
  266. NSData *data = dataM;
  267. // 可变请求
  268. NSURL *url = [NSURL URLWithString:urlString];
  269. NSMutableURLRequest *requestM = [NSMutableURLRequest requestWithURL:url
  270. cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:JSON_TIMEOUT];
  271. // line note
  272. requestM.HTTPMethod = @"POST";
  273. // request header
  274. [requestM addValue:@"close" forHTTPHeaderField:@"Connection"];
  275. [requestM addValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@",BOUNDARY] forHTTPHeaderField:@"Content-Type"];
  276. [requestM addValue:@"multipart/form-data" forHTTPHeaderField:@"enctype"];
  277. [requestM addValue:[NSString stringWithFormat:@"%lu", (unsigned long)[data length]] forHTTPHeaderField:@"Content-Length"];
  278. // request body
  279. requestM.HTTPBody = data;
  280. NSURLSession *urlSession = [self standSession];
  281. if (urlSession.delegate) {
  282. if ([urlSession.delegate isKindOfClass:[RANetworkTaskDelegate class]]) {
  283. RANetworkTaskDelegate *delegate = (RANetworkTaskDelegate *)urlSession.delegate;
  284. if (p) {
  285. delegate.p = p;
  286. }
  287. if (r) {
  288. delegate.r = r;
  289. }
  290. if (decrypt) {
  291. delegate.decryptHandler = decrypt;
  292. }
  293. }
  294. }
  295. NSURLSessionDataTask *dataTask = [urlSession uploadTaskWithRequest:requestM fromData:data];
  296. [dataTask resume];
  297. return dataTask;
  298. }
  299. + (NSURLSessionTask *)upload:(NSString *)filePath Params:(NSDictionary *)params ToHost:(NSString *)urlString Result:(resultHandler)r Progress:(progressHandler)p DecryptHandler:(id (^)(NSString *))decrypt {
  300. NSString *fileName = [filePath lastPathComponent];
  301. NSData *file_data = [NSData dataWithContentsOfFile:filePath];
  302. return [self upload:file_data FileName:fileName Params:params ToHost:urlString Result:r Progress:p DecryptHandler:decrypt];
  303. //
  304. // NSMutableData *dataM = [NSMutableData data];
  305. //
  306. // NSMutableString *stringM = [NSMutableString string];
  307. //
  308. //
  309. // DebugLog(@"================parms==================");
  310. //
  311. //
  312. //
  313. // for (NSString *key in params) {
  314. //
  315. // [stringM appendString:[NSString stringWithFormat:@"--%@\r\n",BOUNDARY]];
  316. // [stringM appendFormat:@"Content-Type: text/plain; charset=UTF-8\r\n"];
  317. // [stringM appendFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n",key];
  318. // [stringM appendFormat:@"%@\r\n",[params objectForKey:key]];
  319. //
  320. //
  321. // DebugLog(@"parameter: key=%@ value=%@",key,[params objectForKey:key]);
  322. // }
  323. // DebugLog(@"================parms==================");
  324. // [stringM appendString:[NSString stringWithFormat:@"--%@\r\n",BOUNDARY]];
  325. //
  326. // [stringM appendFormat:@"Content-Disposition: form-data; name=\"upfile\"; filename=%@\r\n",fileName];
  327. // [stringM appendString:@"Content-Type: application/mac-binary\r\n"];
  328. // [stringM appendString:@"\r\n"];
  329. //
  330. // NSData *stringM_data = [stringM dataUsingEncoding:NSUTF8StringEncoding];
  331. // [dataM appendData:stringM_data];
  332. //
  333. // NSData *file_data = [NSData dataWithContentsOfFile:filePath];
  334. // [dataM appendData:file_data];
  335. //
  336. // NSString *end = [NSString stringWithFormat:@"\r\n--%@--",BOUNDARY];
  337. // [dataM appendData:[end dataUsingEncoding:NSUTF8StringEncoding]];
  338. //
  339. // // Data
  340. // NSData *data = dataM;
  341. //
  342. //
  343. // // 可变请求
  344. // NSURL *url = [NSURL URLWithString:urlString];
  345. // NSMutableURLRequest *requestM = [NSMutableURLRequest requestWithURL:url
  346. // cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:JSON_TIMEOUT];
  347. // // line note
  348. // requestM.HTTPMethod = @"POST";
  349. //
  350. // // request header
  351. // [requestM addValue:@"close" forHTTPHeaderField:@"Connection"];
  352. //
  353. // [requestM addValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@",BOUNDARY] forHTTPHeaderField:@"Content-Type"];
  354. //
  355. // [requestM addValue:[NSString stringWithFormat:@"%lu", (unsigned long)[data length]] forHTTPHeaderField:@"Content-Length"];
  356. //
  357. // // request body
  358. // requestM.HTTPBody = data;
  359. //
  360. //
  361. //
  362. // NSURLSession *urlSession = [self standSession];
  363. //
  364. // if (urlSession.delegate) {
  365. // if ([urlSession.delegate isKindOfClass:[RANetworkTaskDelegate class]]) {
  366. //
  367. // RANetworkTaskDelegate *delegate = (RANetworkTaskDelegate *)urlSession.delegate;
  368. //
  369. // if (p) {
  370. // delegate.p = p;
  371. // }
  372. //
  373. // if (r) {
  374. // delegate.r = r;
  375. // }
  376. //
  377. // if (decrypt) {
  378. // delegate.decryptHandler = decrypt;
  379. // }
  380. //
  381. // }
  382. // }
  383. //
  384. // NSURLSessionDataTask *dataTask = [urlSession uploadTaskWithRequest:requestM fromData:data];
  385. //
  386. // [dataTask resume];
  387. //
  388. // return dataTask;
  389. }
  390. + (NSURLSession *)standSession {
  391. NSURLSession *session = nil;
  392. RANetworkTaskDelegate *delegate = [RANetworkTaskDelegate sharedInstance];
  393. NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
  394. config.timeoutIntervalForRequest = JSON_TIMEOUT;
  395. NSOperationQueue *queue = [[NSOperationQueue alloc] init];
  396. session = [NSURLSession sessionWithConfiguration:config delegate:delegate delegateQueue:queue];
  397. return session;
  398. }
  399. + (NSURLSessionDataTask *)downloadFileOffset:(NSUInteger)offset Param:(NSDictionary *)param from:(NSString *)url method:(NSString *)method toPath:(NSString *)path progressHandler:(progressHandler)progressHandler completionHandler:(resultHandler)result {
  400. NSURLSession *sessoin = [self standSession];
  401. RANetworkTaskDelegate *delegate = (RANetworkTaskDelegate *)sessoin.delegate;
  402. delegate.downloadTask = YES;
  403. delegate.fileCachePath = path;
  404. if (progressHandler) {
  405. delegate.p = progressHandler;
  406. }
  407. if (result) {
  408. delegate.r = result;
  409. }
  410. NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
  411. req.HTTPMethod = method;
  412. if (offset > 0) {
  413. [req addValue:[NSString stringWithFormat:@"bytes=%ld-",(unsigned long)offset] forHTTPHeaderField:@"Range"];
  414. }
  415. // 拼接参数
  416. if (param && param.allValues.count > 0) {
  417. __block NSMutableArray *paramArr = [NSMutableArray array];
  418. [param enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
  419. [paramArr addObject:[NSString stringWithFormat:@"%@=%@",key,obj]];
  420. }];
  421. NSString *paramStr = [paramArr componentsJoinedByString:@"&"];
  422. req.HTTPBody = [paramStr dataUsingEncoding:NSUTF8StringEncoding];
  423. }
  424. NSURLSessionDataTask *downloadTask = [sessoin dataTaskWithRequest:req];
  425. [downloadTask resume];
  426. return downloadTask;
  427. }
  428. #pragma mark new interface
  429. +(NSMutableDictionary*) prepare_addtional_params:(NSMutableDictionary* ) params
  430. {
  431. //
  432. // NSString *userAction = [params valueForKey:kAction];
  433. // NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  434. // if ([userAction isEqualToString:@"Login"]) {
  435. // if (!extra) {
  436. // extra = [NSMutableDictionary dictionary];
  437. // }
  438. // [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  439. // }
  440. return params;
  441. }
  442. +(NSData*)request_interface_d : (NSString*) url parameters:(NSMutableDictionary *) params err_record_url:(NSString* )recorder_url completionHandler:(resultHandler)result retry:(int) retry
  443. {
  444. // __block int retry = 0;
  445. if(![NetworkUtils IsNetworkAvailable])
  446. {
  447. dispatch_async(dispatch_get_main_queue(), ^{
  448. if(result)
  449. result([[RAConvertor string2dict:[NSString stringWithFormat:@"{'result':%d}",RESULT_NET_NOTAVAILABLE]] mutableCopy]);
  450. });
  451. // return detailContent;
  452. return nil;
  453. }
  454. params = [self prepare_addtional_params:params];
  455. //repeat:
  456. // {
  457. // return [self fake_json:url];
  458. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  459. //分界线的标识符
  460. NSString *TWITTERFON_FORM_BOUNDARY = @"AaB03x";
  461. //根据url初始化request
  462. NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
  463. cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
  464. timeoutInterval:JSON_TIMEOUT];
  465. //分界线 --AaB03x
  466. NSString *MPboundary=[[NSString alloc]initWithFormat:@"--%@",TWITTERFON_FORM_BOUNDARY];
  467. //结束符 AaB03x--
  468. NSString *endMPboundary=[[NSString alloc]initWithFormat:@"%@--",MPboundary];
  469. //要上传的图片
  470. // UIImage *image=[params objectForKey:@"pic"];
  471. //得到图片的data
  472. /*
  473. // NSData* data = [NSData dataWithContentsOfFile:file_path];
  474. */
  475. //http body的字符串
  476. NSMutableString *body=[[NSMutableString alloc]init];
  477. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  478. // [params setValue:@"handset_login" forKey:@"action"];
  479. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  480. // [params setValue:appDelegate.sessionid forKey:@"sessionid"];
  481. // [params setValue:password forKey:@"password"];
  482. // [params setValue:[NSString stringWithFormat:@"%d",ver] forKey:@"auth_ver"];
  483. // [headers setValue:headQuerlString forKey:@"param"];
  484. //参数的集合的所有key的集合
  485. NSArray *keys= [params allKeys];
  486. DebugLog(@"================parms==================");
  487. //遍历keys
  488. for(int i=0;i<[keys count];i++)
  489. {
  490. //得到当前key
  491. NSString *key=[keys objectAtIndex:i];
  492. //如果key不是pic,说明value是字符类型,比如name:Boris
  493. if(![key isEqualToString:@"pic"])
  494. {
  495. //添加分界线,换行
  496. [body appendFormat:@"%@\r\n",MPboundary];
  497. //添加字段名称,换2行
  498. [body appendFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n",key];
  499. //添加字段的值
  500. [body appendFormat:@"%@\r\n",[params objectForKey:key]];
  501. DebugLog(@"parameter: key=%@ value=%@",key,[params objectForKey:key]);
  502. }
  503. }
  504. DebugLog(@"================parms==================");
  505. ////添加分界线,换行
  506. /* [body appendFormat:@"%@\r\n",MPboundary];
  507. //声明pic字段,文件名为boris.png
  508. NSString * file_format=[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"upfile\"; filename=\"%@\"\r\n", [file_path lastPathComponent]];
  509. [body appendFormat:@"%@", file_format];
  510. //声明上传文件的格式
  511. [body appendFormat:@"Content-Type: application/zip\r\n\r\n"];
  512. */
  513. //声明结束符:--AaB03x--
  514. NSString *end=[[NSString alloc]initWithFormat:@"\r\n%@",endMPboundary];
  515. //声明myRequestData,用来放入http body
  516. NSMutableData *myRequestData=[NSMutableData data];
  517. //将body字符串转化为UTF8格式的二进制
  518. [myRequestData appendData:[body dataUsingEncoding:NSUTF8StringEncoding]];
  519. /*
  520. //将image的data加入
  521. [myRequestData appendData:data];
  522. */
  523. //加入结束符--AaB03x--
  524. [myRequestData appendData:[end dataUsingEncoding:NSUTF8StringEncoding]];
  525. //设置HTTPHeader中Content-Type的值
  526. NSString *content=[[NSString alloc]initWithFormat:@"multipart/form-data; boundary=%@",TWITTERFON_FORM_BOUNDARY];
  527. //设置HTTPHeader
  528. [request setValue:content forHTTPHeaderField:@"Content-Type"];
  529. [request setValue:@"multipart/form-data" forHTTPHeaderField:@"enctype"];
  530. // 关闭keep alive
  531. [request setValue:@"close" forHTTPHeaderField:@"Connection"];
  532. //设置Content-Length
  533. [request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[myRequestData length]] forHTTPHeaderField:@"Content-Length"];
  534. //设置http body
  535. [request setHTTPBody:myRequestData];
  536. //http method
  537. [request setHTTPMethod:@"POST"];
  538. NSLog([[NSString alloc] initWithData:myRequestData encoding:NSUTF8StringEncoding]);
  539. NSURLSession *urlSession = [self standSession];
  540. if (urlSession.delegate) {
  541. if ([urlSession.delegate isKindOfClass:[RANetworkTaskDelegate class]]) {
  542. RANetworkTaskDelegate *delegate = (RANetworkTaskDelegate *)urlSession.delegate;
  543. // if (p) {
  544. // delegate.p = p;
  545. // }
  546. //
  547. if (result) {
  548. delegate.r = result;
  549. }
  550. //
  551. // if (decrypt) {
  552. // delegate.decryptHandler = decrypt;
  553. // }
  554. }
  555. }
  556. NSURLSessionDataTask *dataTask = [urlSession dataTaskWithRequest:request];
  557. // [dataTask1 resume];
  558. // NSURLSessionDataTask *dataTask =[urlSession dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
  559. //
  560. // NSData *responseData =data;
  561. // NSHTTPURLResponse* urlResponse =response;
  562. // if (responseData==nil) {
  563. //
  564. // // DebugLog(@"response error:%@", [error localizedDescription]);
  565. //
  566. //
  567. // NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
  568. // //#define RESULT_FALSE 0
  569. // //#define RESULT_TRUE 2
  570. // //#define RESULT_NET_ERROR -3
  571. // //#define RESULT_NET_NOTAVAILABLE -4
  572. // //#define RESULT_ERROR -5
  573. // //#define RESULT_LOCALFILE_ERROR -7
  574. // //#define RESULT_USERAUTH_ERROR -9
  575. // //#define RESULT_UPDATE_USERAUTH_ERROR -11
  576. // //#define RESULT_SESSION_EXPIRED -13
  577. // //#define RESULT_VER_LOW
  578. //
  579. // // NSString * moreinfo = error.description ;
  580. //
  581. // NSString* err_msg = [error localizedDescription];
  582. //
  583. //
  584. // //-----------------retry 3 times for error code -1005------------------------
  585. // if(error.code==-1005&&retry<3)
  586. // {
  587. // int new_retry=retry+1;
  588. // [self request_interface:url parameters:params err_record_url:recorder_url completionHandler:result retry:new_retry];
  589. // return;
  590. // // retry++;
  591. // // goto repeat;
  592. //
  593. // }
  594. // //-----------------end retry 3 times for error code -1005------------------------
  595. //
  596. // NSDictionary* error_json = [RAUtils error_dict:error];
  597. // [ret setObject:error_json forKey:@"err_obj"];
  598. // NSString* resp_msg= nil;
  599. //
  600. // if(err_msg.length==0)
  601. // {
  602. // err_msg =[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode];
  603. // resp_msg = err_msg;
  604. // }
  605. // [ret setValue:[NSString stringWithFormat:@"%d",RESULT_NET_ERROR] forKey:@"result"];
  606. // [ret setValue:err_msg forKey:@"err_msg"];
  607. // [ret setValue:resp_msg forKey:@"resp_msg"];
  608. // [ret setValue:[NSString stringWithFormat:@"%ld",(long)urlResponse.statusCode] forKey:@"resp_code"];
  609. //
  610. //
  611. // NSData *jsonData = [NSJSONSerialization dataWithJSONObject:ret
  612. // options:0
  613. // error:nil];
  614. // if(![url isEqualToString:recorder_url])
  615. // {
  616. // [self err_log:[RAUtils base64en:[RAConvertor dict2string:params]] result:[RAUtils base64en:[RAConvertor dict2string:ret]] module:url code:RESULT_NET_ERROR];
  617. // }
  618. // dispatch_async(dispatch_get_main_queue(), ^{
  619. // if(result)
  620. // return result([[RAConvertor data2dict:jsonData] mutableCopy]);
  621. // });
  622. // }
  623. // else
  624. // {
  625. // NSDictionary* dict =[RAConvertor data2dict:responseData];
  626. // dispatch_async(dispatch_get_main_queue(), ^{
  627. // if(result)
  628. // return result([[RAConvertor data2dict:responseData] mutableCopy]);
  629. // });
  630. //
  631. // }
  632. //
  633. // }];
  634. //// NSURLSessionDataTask *dataTask = [urlSession dataTaskWithRequest:request ];
  635. //
  636. [dataTask resume];
  637. return nil;
  638. //
  639. //
  640. // NSHTTPURLResponse* urlResponse = nil;
  641. //
  642. // NSError *error = nil;
  643. // NSLog(@"begin request %@",url);
  644. //
  645. // NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
  646. //
  647. //
  648. // DebugLog(@"url: %@",url);
  649. //
  650. // DebugLog(@"response: %@",[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode]);
  651. //
  652. //
  653. // NSLog(@"get response");
  654. // if (responseData==nil) {
  655. //
  656. // // DebugLog(@"response error:%@", [error localizedDescription]);
  657. //
  658. //
  659. // NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
  660. // //#define RESULT_FALSE 0
  661. // //#define RESULT_TRUE 2
  662. // //#define RESULT_NET_ERROR -3
  663. // //#define RESULT_NET_NOTAVAILABLE -4
  664. // //#define RESULT_ERROR -5
  665. // //#define RESULT_LOCALFILE_ERROR -7
  666. // //#define RESULT_USERAUTH_ERROR -9
  667. // //#define RESULT_UPDATE_USERAUTH_ERROR -11
  668. // //#define RESULT_SESSION_EXPIRED -13
  669. // //#define RESULT_VER_LOW
  670. //
  671. // // NSString * moreinfo = error.description ;
  672. //
  673. // NSString* err_msg = [error localizedDescription];
  674. //
  675. //
  676. // //-----------------retry 3 times for error code -1005------------------------
  677. // if(error.code==-1005&&retry<3)
  678. // {
  679. // retry++;
  680. // goto repeat;
  681. //
  682. // }
  683. // //-----------------end retry 3 times for error code -1005------------------------
  684. //
  685. // NSDictionary* error_json = [RAUtils error_dict:error];
  686. // [ret setObject:error_json forKey:@"err_obj"];
  687. // NSString* resp_msg= nil;
  688. //
  689. // if(err_msg.length==0)
  690. // {
  691. // err_msg =[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode];
  692. // resp_msg = err_msg;
  693. // }
  694. // [ret setValue:[NSString stringWithFormat:@"%d",RESULT_NET_ERROR] forKey:@"result"];
  695. // [ret setValue:err_msg forKey:@"err_msg"];
  696. // [ret setValue:resp_msg forKey:@"resp_msg"];
  697. // [ret setValue:[NSString stringWithFormat:@"%ld",(long)urlResponse.statusCode] forKey:@"resp_code"];
  698. //
  699. //
  700. // NSData *jsonData = [NSJSONSerialization dataWithJSONObject:ret
  701. // options:0
  702. // error:nil];
  703. // if(![url isEqualToString:recorder_url])
  704. // {
  705. // [self err_log:[RAUtils base64en:[RAConvertor dict2string:params]] result:[RAUtils base64en:[RAConvertor dict2string:ret]] module:url code:RESULT_NET_ERROR];
  706. // }
  707. // return jsonData;
  708. //
  709. // }
  710. // else
  711. // {
  712. // // NSString* err_msg = [error localizedDescription];
  713. // NSMutableString *str = [[NSMutableString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
  714. //
  715. // DebugLog(@"data string: %@",str);
  716. // NSError *error1 = nil;
  717. //
  718. // NSMutableDictionary* jsobj = [[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error1] mutableCopy];
  719. //
  720. // if(jsobj==nil)// 服务器返回不是json
  721. // {
  722. //
  723. // jsobj=[[NSMutableDictionary alloc] init];
  724. // [jsobj setValue:[NSNumber numberWithInt:RESULT_NO_RESPONSE] forKey:@"result"];
  725. //
  726. // }
  727. //// if([jsobj[@"encrypt"] boolValue]==true)
  728. //// {
  729. //// jsobj = decryptBlock(jsobj);
  730. //// }
  731. //// if (resultBlock) {
  732. //// jsobj = resultBlock(jsobj);
  733. //// }
  734. //
  735. // int result=[[jsobj valueForKey:@"result"] intValue];
  736. // if(![url isEqualToString:recorder_url]&&/*![url isEqualToString:URL_DOWNLOAD_OFFLINE]&&*/result!=2&&result!=99)
  737. // {
  738. // [self err_log:[RAUtils base64en:[RAConvertor dict2string:params]] result:[RAUtils base64en:str] module:url code:result];
  739. // }
  740. // NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsobj
  741. // options:0
  742. // error:nil];
  743. // return jsonData;
  744. //
  745. // }
  746. // return responseData;
  747. // }
  748. }
  749. +(NSData*)request_interface : (NSString*) url parameters:(NSMutableDictionary *) params err_record_url:(NSString* )recorder_url completionHandler:(resultHandler)result retry:(int) retry
  750. {
  751. // __block int retry = 0;
  752. if(![NetworkUtils IsNetworkAvailable])
  753. {
  754. dispatch_async(dispatch_get_main_queue(), ^{
  755. if(result)
  756. result([[RAConvertor string2dict:[NSString stringWithFormat:@"{'result':%d}",RESULT_NET_NOTAVAILABLE]] mutableCopy]);
  757. });
  758. // return detailContent;
  759. return nil;
  760. }
  761. params = [self prepare_addtional_params:params];
  762. //repeat:
  763. // {
  764. // return [self fake_json:url];
  765. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  766. //分界线的标识符
  767. NSString *TWITTERFON_FORM_BOUNDARY = @"AaB03x";
  768. //根据url初始化request
  769. NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
  770. cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
  771. timeoutInterval:JSON_TIMEOUT];
  772. //分界线 --AaB03x
  773. NSString *MPboundary=[[NSString alloc]initWithFormat:@"--%@",TWITTERFON_FORM_BOUNDARY];
  774. //结束符 AaB03x--
  775. NSString *endMPboundary=[[NSString alloc]initWithFormat:@"%@--",MPboundary];
  776. //要上传的图片
  777. // UIImage *image=[params objectForKey:@"pic"];
  778. //得到图片的data
  779. /*
  780. // NSData* data = [NSData dataWithContentsOfFile:file_path];
  781. */
  782. //http body的字符串
  783. NSMutableString *body=[[NSMutableString alloc]init];
  784. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  785. // [params setValue:@"handset_login" forKey:@"action"];
  786. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  787. // [params setValue:appDelegate.sessionid forKey:@"sessionid"];
  788. // [params setValue:password forKey:@"password"];
  789. // [params setValue:[NSString stringWithFormat:@"%d",ver] forKey:@"auth_ver"];
  790. // [headers setValue:headQuerlString forKey:@"param"];
  791. //参数的集合的所有key的集合
  792. NSArray *keys= [params allKeys];
  793. DebugLog(@"================parms==================");
  794. //遍历keys
  795. for(int i=0;i<[keys count];i++)
  796. {
  797. //得到当前key
  798. NSString *key=[keys objectAtIndex:i];
  799. //如果key不是pic,说明value是字符类型,比如name:Boris
  800. if(![key isEqualToString:@"pic"])
  801. {
  802. //添加分界线,换行
  803. [body appendFormat:@"%@\r\n",MPboundary];
  804. //添加字段名称,换2行
  805. [body appendFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n",key];
  806. //添加字段的值
  807. [body appendFormat:@"%@\r\n",[params objectForKey:key]];
  808. DebugLog(@"parameter: key=%@ value=%@",key,[params objectForKey:key]);
  809. }
  810. }
  811. DebugLog(@"================parms==================");
  812. ////添加分界线,换行
  813. /* [body appendFormat:@"%@\r\n",MPboundary];
  814. //声明pic字段,文件名为boris.png
  815. NSString * file_format=[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"upfile\"; filename=\"%@\"\r\n", [file_path lastPathComponent]];
  816. [body appendFormat:@"%@", file_format];
  817. //声明上传文件的格式
  818. [body appendFormat:@"Content-Type: application/zip\r\n\r\n"];
  819. */
  820. //声明结束符:--AaB03x--
  821. NSString *end=[[NSString alloc]initWithFormat:@"\r\n%@",endMPboundary];
  822. //声明myRequestData,用来放入http body
  823. NSMutableData *myRequestData=[NSMutableData data];
  824. //将body字符串转化为UTF8格式的二进制
  825. [myRequestData appendData:[body dataUsingEncoding:NSUTF8StringEncoding]];
  826. /*
  827. //将image的data加入
  828. [myRequestData appendData:data];
  829. */
  830. //加入结束符--AaB03x--
  831. [myRequestData appendData:[end dataUsingEncoding:NSUTF8StringEncoding]];
  832. //设置HTTPHeader中Content-Type的值
  833. NSString *content=[[NSString alloc]initWithFormat:@"multipart/form-data; boundary=%@",TWITTERFON_FORM_BOUNDARY];
  834. //设置HTTPHeader
  835. [request setValue:content forHTTPHeaderField:@"Content-Type"];
  836. [request setValue:@"multipart/form-data" forHTTPHeaderField:@"enctype"];
  837. // 关闭keep alive
  838. [request setValue:@"close" forHTTPHeaderField:@"Connection"];
  839. //设置Content-Length
  840. [request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[myRequestData length]] forHTTPHeaderField:@"Content-Length"];
  841. //设置http body
  842. [request setHTTPBody:myRequestData];
  843. //http method
  844. [request setHTTPMethod:@"POST"];
  845. NSURLSession *urlSession = [self standSession];
  846. if (urlSession.delegate) {
  847. if ([urlSession.delegate isKindOfClass:[RANetworkTaskDelegate class]]) {
  848. RANetworkTaskDelegate *delegate = (RANetworkTaskDelegate *)urlSession.delegate;
  849. // if (p) {
  850. // delegate.p = p;
  851. // }
  852. //
  853. if (result) {
  854. delegate.r = result;
  855. }
  856. //
  857. // if (decrypt) {
  858. // delegate.decryptHandler = decrypt;
  859. // }
  860. }
  861. }
  862. NSURLSessionDataTask *dataTask =[urlSession dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
  863. NSData *responseData =data;
  864. NSHTTPURLResponse* urlResponse =response;
  865. if (responseData==nil) {
  866. // DebugLog(@"response error:%@", [error localizedDescription]);
  867. NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
  868. //#define RESULT_FALSE 0
  869. //#define RESULT_TRUE 2
  870. //#define RESULT_NET_ERROR -3
  871. //#define RESULT_NET_NOTAVAILABLE -4
  872. //#define RESULT_ERROR -5
  873. //#define RESULT_LOCALFILE_ERROR -7
  874. //#define RESULT_USERAUTH_ERROR -9
  875. //#define RESULT_UPDATE_USERAUTH_ERROR -11
  876. //#define RESULT_SESSION_EXPIRED -13
  877. //#define RESULT_VER_LOW
  878. // NSString * moreinfo = error.description ;
  879. NSString* err_msg = [error localizedDescription];
  880. //-----------------retry 3 times for error code -1005------------------------
  881. if(error.code==-1005&&retry<3)
  882. {
  883. int new_retry=retry+1;
  884. [self request_interface:url parameters:params err_record_url:recorder_url completionHandler:result retry:new_retry];
  885. return;
  886. // retry++;
  887. // goto repeat;
  888. }
  889. //-----------------end retry 3 times for error code -1005------------------------
  890. NSDictionary* error_json = [RAUtils error_dict:error];
  891. [ret setObject:error_json forKey:@"err_obj"];
  892. NSString* resp_msg= nil;
  893. if(err_msg.length==0)
  894. {
  895. err_msg =[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode];
  896. resp_msg = err_msg;
  897. }
  898. [ret setValue:[NSString stringWithFormat:@"%d",RESULT_NET_ERROR] forKey:@"result"];
  899. [ret setValue:err_msg forKey:@"err_msg"];
  900. [ret setValue:resp_msg forKey:@"resp_msg"];
  901. [ret setValue:[NSString stringWithFormat:@"%ld",(long)urlResponse.statusCode] forKey:@"resp_code"];
  902. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:ret
  903. options:0
  904. error:nil];
  905. if(![url isEqualToString:recorder_url])
  906. {
  907. [self err_log:[RAUtils base64en:[RAConvertor dict2string:params]] result:[RAUtils base64en:[RAConvertor dict2string:ret]] module:url code:RESULT_NET_ERROR];
  908. }
  909. dispatch_async(dispatch_get_main_queue(), ^{
  910. if(result)
  911. return result([[RAConvertor data2dict:jsonData] mutableCopy]);
  912. });
  913. }
  914. else
  915. {
  916. NSDictionary* dict =[RAConvertor data2dict:responseData];
  917. dispatch_async(dispatch_get_main_queue(), ^{
  918. if(result)
  919. return result([[RAConvertor data2dict:responseData] mutableCopy]);
  920. });
  921. }
  922. }];
  923. // NSURLSessionDataTask *dataTask = [urlSession dataTaskWithRequest:request ];
  924. [dataTask resume];
  925. return nil;
  926. //
  927. //
  928. // NSHTTPURLResponse* urlResponse = nil;
  929. //
  930. // NSError *error = nil;
  931. // NSLog(@"begin request %@",url);
  932. //
  933. // NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
  934. //
  935. //
  936. // DebugLog(@"url: %@",url);
  937. //
  938. // DebugLog(@"response: %@",[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode]);
  939. //
  940. //
  941. // NSLog(@"get response");
  942. // if (responseData==nil) {
  943. //
  944. // // DebugLog(@"response error:%@", [error localizedDescription]);
  945. //
  946. //
  947. // NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
  948. // //#define RESULT_FALSE 0
  949. // //#define RESULT_TRUE 2
  950. // //#define RESULT_NET_ERROR -3
  951. // //#define RESULT_NET_NOTAVAILABLE -4
  952. // //#define RESULT_ERROR -5
  953. // //#define RESULT_LOCALFILE_ERROR -7
  954. // //#define RESULT_USERAUTH_ERROR -9
  955. // //#define RESULT_UPDATE_USERAUTH_ERROR -11
  956. // //#define RESULT_SESSION_EXPIRED -13
  957. // //#define RESULT_VER_LOW
  958. //
  959. // // NSString * moreinfo = error.description ;
  960. //
  961. // NSString* err_msg = [error localizedDescription];
  962. //
  963. //
  964. // //-----------------retry 3 times for error code -1005------------------------
  965. // if(error.code==-1005&&retry<3)
  966. // {
  967. // retry++;
  968. // goto repeat;
  969. //
  970. // }
  971. // //-----------------end retry 3 times for error code -1005------------------------
  972. //
  973. // NSDictionary* error_json = [RAUtils error_dict:error];
  974. // [ret setObject:error_json forKey:@"err_obj"];
  975. // NSString* resp_msg= nil;
  976. //
  977. // if(err_msg.length==0)
  978. // {
  979. // err_msg =[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode];
  980. // resp_msg = err_msg;
  981. // }
  982. // [ret setValue:[NSString stringWithFormat:@"%d",RESULT_NET_ERROR] forKey:@"result"];
  983. // [ret setValue:err_msg forKey:@"err_msg"];
  984. // [ret setValue:resp_msg forKey:@"resp_msg"];
  985. // [ret setValue:[NSString stringWithFormat:@"%ld",(long)urlResponse.statusCode] forKey:@"resp_code"];
  986. //
  987. //
  988. // NSData *jsonData = [NSJSONSerialization dataWithJSONObject:ret
  989. // options:0
  990. // error:nil];
  991. // if(![url isEqualToString:recorder_url])
  992. // {
  993. // [self err_log:[RAUtils base64en:[RAConvertor dict2string:params]] result:[RAUtils base64en:[RAConvertor dict2string:ret]] module:url code:RESULT_NET_ERROR];
  994. // }
  995. // return jsonData;
  996. //
  997. // }
  998. // else
  999. // {
  1000. // // NSString* err_msg = [error localizedDescription];
  1001. // NSMutableString *str = [[NSMutableString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
  1002. //
  1003. // DebugLog(@"data string: %@",str);
  1004. // NSError *error1 = nil;
  1005. //
  1006. // NSMutableDictionary* jsobj = [[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error1] mutableCopy];
  1007. //
  1008. // if(jsobj==nil)// 服务器返回不是json
  1009. // {
  1010. //
  1011. // jsobj=[[NSMutableDictionary alloc] init];
  1012. // [jsobj setValue:[NSNumber numberWithInt:RESULT_NO_RESPONSE] forKey:@"result"];
  1013. //
  1014. // }
  1015. //// if([jsobj[@"encrypt"] boolValue]==true)
  1016. //// {
  1017. //// jsobj = decryptBlock(jsobj);
  1018. //// }
  1019. //// if (resultBlock) {
  1020. //// jsobj = resultBlock(jsobj);
  1021. //// }
  1022. //
  1023. // int result=[[jsobj valueForKey:@"result"] intValue];
  1024. // if(![url isEqualToString:recorder_url]&&/*![url isEqualToString:URL_DOWNLOAD_OFFLINE]&&*/result!=2&&result!=99)
  1025. // {
  1026. // [self err_log:[RAUtils base64en:[RAConvertor dict2string:params]] result:[RAUtils base64en:str] module:url code:result];
  1027. // }
  1028. // NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsobj
  1029. // options:0
  1030. // error:nil];
  1031. // return jsonData;
  1032. //
  1033. // }
  1034. // return responseData;
  1035. // }
  1036. }
  1037. +(NSData*)request_file : (NSString*) url parameters:(NSMutableDictionary *) params err_record_url:(NSString* )recorder_url completionHandler:(resultHandler)result
  1038. /* dataHandler:(dataHandler)returndata*/
  1039. {
  1040. // __block int retry = 0;
  1041. if(![NetworkUtils IsNetworkAvailable])
  1042. {
  1043. dispatch_async(dispatch_get_main_queue(), ^{
  1044. if(result)
  1045. result([[RAConvertor string2dict:[NSString stringWithFormat:@"{'result':%d}",RESULT_NET_NOTAVAILABLE]] mutableCopy]);
  1046. });
  1047. // return detailContent;
  1048. return nil;
  1049. }
  1050. params = [self prepare_addtional_params:params];
  1051. //repeat:
  1052. // {
  1053. // return [self fake_json:url];
  1054. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1055. //分界线的标识符
  1056. NSString *TWITTERFON_FORM_BOUNDARY = @"AaB03x";
  1057. //根据url初始化request
  1058. NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
  1059. cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
  1060. timeoutInterval:JSON_TIMEOUT];
  1061. //分界线 --AaB03x
  1062. NSString *MPboundary=[[NSString alloc]initWithFormat:@"--%@",TWITTERFON_FORM_BOUNDARY];
  1063. //结束符 AaB03x--
  1064. NSString *endMPboundary=[[NSString alloc]initWithFormat:@"%@--",MPboundary];
  1065. //要上传的图片
  1066. // UIImage *image=[params objectForKey:@"pic"];
  1067. //得到图片的data
  1068. /*
  1069. // NSData* data = [NSData dataWithContentsOfFile:file_path];
  1070. */
  1071. //http body的字符串
  1072. NSMutableString *body=[[NSMutableString alloc]init];
  1073. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1074. // [params setValue:@"handset_login" forKey:@"action"];
  1075. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  1076. // [params setValue:appDelegate.sessionid forKey:@"sessionid"];
  1077. // [params setValue:password forKey:@"password"];
  1078. // [params setValue:[NSString stringWithFormat:@"%d",ver] forKey:@"auth_ver"];
  1079. // [headers setValue:headQuerlString forKey:@"param"];
  1080. //参数的集合的所有key的集合
  1081. NSArray *keys= [params allKeys];
  1082. DebugLog(@"================parms==================");
  1083. //遍历keys
  1084. for(int i=0;i<[keys count];i++)
  1085. {
  1086. //得到当前key
  1087. NSString *key=[keys objectAtIndex:i];
  1088. //如果key不是pic,说明value是字符类型,比如name:Boris
  1089. if(![key isEqualToString:@"pic"])
  1090. {
  1091. //添加分界线,换行
  1092. [body appendFormat:@"%@\r\n",MPboundary];
  1093. //添加字段名称,换2行
  1094. [body appendFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n",key];
  1095. //添加字段的值
  1096. [body appendFormat:@"%@\r\n",[params objectForKey:key]];
  1097. DebugLog(@"parameter: key=%@ value=%@",key,[params objectForKey:key]);
  1098. }
  1099. }
  1100. DebugLog(@"================parms==================");
  1101. ////添加分界线,换行
  1102. /* [body appendFormat:@"%@\r\n",MPboundary];
  1103. //声明pic字段,文件名为boris.png
  1104. NSString * file_format=[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"upfile\"; filename=\"%@\"\r\n", [file_path lastPathComponent]];
  1105. [body appendFormat:@"%@", file_format];
  1106. //声明上传文件的格式
  1107. [body appendFormat:@"Content-Type: application/zip\r\n\r\n"];
  1108. */
  1109. //声明结束符:--AaB03x--
  1110. NSString *end=[[NSString alloc]initWithFormat:@"\r\n%@",endMPboundary];
  1111. //声明myRequestData,用来放入http body
  1112. NSMutableData *myRequestData=[NSMutableData data];
  1113. //将body字符串转化为UTF8格式的二进制
  1114. [myRequestData appendData:[body dataUsingEncoding:NSUTF8StringEncoding]];
  1115. /*
  1116. //将image的data加入
  1117. [myRequestData appendData:data];
  1118. */
  1119. //加入结束符--AaB03x--
  1120. [myRequestData appendData:[end dataUsingEncoding:NSUTF8StringEncoding]];
  1121. //设置HTTPHeader中Content-Type的值
  1122. NSString *content=[[NSString alloc]initWithFormat:@"multipart/form-data; boundary=%@",TWITTERFON_FORM_BOUNDARY];
  1123. //设置HTTPHeader
  1124. [request setValue:content forHTTPHeaderField:@"Content-Type"];
  1125. [request setValue:@"multipart/form-data" forHTTPHeaderField:@"enctype"];
  1126. // 关闭keep alive
  1127. [request setValue:@"close" forHTTPHeaderField:@"Connection"];
  1128. //设置Content-Length
  1129. [request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[myRequestData length]] forHTTPHeaderField:@"Content-Length"];
  1130. //设置http body
  1131. [request setHTTPBody:myRequestData];
  1132. //http method
  1133. [request setHTTPMethod:@"POST"];
  1134. NSURLSession *urlSession = [self standSession];
  1135. if (urlSession.delegate) {
  1136. if ([urlSession.delegate isKindOfClass:[RANetworkTaskDelegate class]]) {
  1137. RANetworkTaskDelegate *delegate = (RANetworkTaskDelegate *)urlSession.delegate;
  1138. // if (p) {
  1139. // delegate.p = p;
  1140. // }
  1141. //
  1142. if (result) {
  1143. delegate.r = result;
  1144. }
  1145. //
  1146. // if (decrypt) {
  1147. // delegate.decryptHandler = decrypt;
  1148. // }
  1149. }
  1150. }
  1151. NSURLSessionDownloadTask* downloadTask=[urlSession downloadTaskWithRequest:request completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
  1152. NSHTTPURLResponse* urlResponse =response;
  1153. NSData* data =[NSData dataWithContentsOfURL:location] ;
  1154. NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
  1155. if(data==nil)
  1156. {
  1157. NSString* err_msg = [error localizedDescription];
  1158. NSDictionary* error_json = [RAUtils error_dict:error];
  1159. [ret setObject:error_json forKey:@"err_obj"];
  1160. NSString* resp_msg= nil;
  1161. if(err_msg.length==0)
  1162. {
  1163. err_msg =[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode];
  1164. resp_msg = err_msg;
  1165. }
  1166. [ret setValue:[NSString stringWithFormat:@"%d",RESULT_NET_ERROR] forKey:@"result"];
  1167. [ret setValue:err_msg forKey:@"err_msg"];
  1168. [ret setValue:resp_msg forKey:@"resp_msg"];
  1169. [ret setValue:[NSString stringWithFormat:@"%ld",(long)urlResponse.statusCode] forKey:@"resp_code"];
  1170. dispatch_async(dispatch_get_main_queue(), ^{
  1171. if(result)
  1172. result(ret);
  1173. });
  1174. }
  1175. else
  1176. {
  1177. ret[@"result"]=@"2";
  1178. ret[@"data"]=data;
  1179. ret[@"path"]=[location absoluteString];
  1180. dispatch_async(dispatch_get_main_queue(), ^{
  1181. if(result)
  1182. result(ret);
  1183. });
  1184. }
  1185. // if(returndata)
  1186. // {
  1187. // returndata(data);
  1188. // }
  1189. }];
  1190. [downloadTask resume];
  1191. return nil;
  1192. //
  1193. // NSURLSessionDataTask *dataTask =[urlSession dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
  1194. //
  1195. // NSData *responseData =data;
  1196. // NSHTTPURLResponse* urlResponse =response;
  1197. // if (responseData==nil) {
  1198. //
  1199. // // DebugLog(@"response error:%@", [error localizedDescription]);
  1200. //
  1201. //
  1202. // NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
  1203. // //#define RESULT_FALSE 0
  1204. // //#define RESULT_TRUE 2
  1205. // //#define RESULT_NET_ERROR -3
  1206. // //#define RESULT_NET_NOTAVAILABLE -4
  1207. // //#define RESULT_ERROR -5
  1208. // //#define RESULT_LOCALFILE_ERROR -7
  1209. // //#define RESULT_USERAUTH_ERROR -9
  1210. // //#define RESULT_UPDATE_USERAUTH_ERROR -11
  1211. // //#define RESULT_SESSION_EXPIRED -13
  1212. // //#define RESULT_VER_LOW
  1213. //
  1214. // // NSString * moreinfo = error.description ;
  1215. //
  1216. // NSString* err_msg = [error localizedDescription];
  1217. //
  1218. //
  1219. // //-----------------retry 3 times for error code -1005------------------------
  1220. // if(error.code==-1005&&retry<3)
  1221. // {
  1222. // int new_retry=retry+1;
  1223. // [self request_interface:url parameters:params err_record_url:recorder_url completionHandler:result retry:new_retry];
  1224. // return;
  1225. // // retry++;
  1226. // // goto repeat;
  1227. //
  1228. // }
  1229. // //-----------------end retry 3 times for error code -1005------------------------
  1230. //
  1231. // NSDictionary* error_json = [RAUtils error_dict:error];
  1232. // [ret setObject:error_json forKey:@"err_obj"];
  1233. // NSString* resp_msg= nil;
  1234. //
  1235. // if(err_msg.length==0)
  1236. // {
  1237. // err_msg =[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode];
  1238. // resp_msg = err_msg;
  1239. // }
  1240. // [ret setValue:[NSString stringWithFormat:@"%d",RESULT_NET_ERROR] forKey:@"result"];
  1241. // [ret setValue:err_msg forKey:@"err_msg"];
  1242. // [ret setValue:resp_msg forKey:@"resp_msg"];
  1243. // [ret setValue:[NSString stringWithFormat:@"%ld",(long)urlResponse.statusCode] forKey:@"resp_code"];
  1244. //
  1245. //
  1246. // NSData *jsonData = [NSJSONSerialization dataWithJSONObject:ret
  1247. // options:0
  1248. // error:nil];
  1249. // if(![url isEqualToString:recorder_url])
  1250. // {
  1251. // [self err_log:[RAUtils base64en:[RAConvertor dict2string:params]] result:[RAUtils base64en:[RAConvertor dict2string:ret]] module:url code:RESULT_NET_ERROR];
  1252. // }
  1253. //
  1254. // if(result)
  1255. // return result([[RAConvertor data2dict:jsonData] mutableCopy]);
  1256. //
  1257. // }
  1258. // else
  1259. // {
  1260. // NSDictionary* dict =[RAConvertor data2dict:responseData];
  1261. // dispatch_async(dispatch_get_main_queue(), ^{
  1262. // if(result)
  1263. // return result([[RAConvertor data2dict:responseData] mutableCopy]);
  1264. // });
  1265. //
  1266. // }
  1267. //
  1268. // }];
  1269. //// NSURLSessionDataTask *dataTask = [urlSession dataTaskWithRequest:request ];
  1270. //
  1271. // [dataTask resume];
  1272. //
  1273. // return nil;
  1274. //
  1275. //
  1276. // NSHTTPURLResponse* urlResponse = nil;
  1277. //
  1278. // NSError *error = nil;
  1279. // NSLog(@"begin request %@",url);
  1280. //
  1281. // NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
  1282. //
  1283. //
  1284. // DebugLog(@"url: %@",url);
  1285. //
  1286. // DebugLog(@"response: %@",[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode]);
  1287. //
  1288. //
  1289. // NSLog(@"get response");
  1290. // if (responseData==nil) {
  1291. //
  1292. // // DebugLog(@"response error:%@", [error localizedDescription]);
  1293. //
  1294. //
  1295. // NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
  1296. // //#define RESULT_FALSE 0
  1297. // //#define RESULT_TRUE 2
  1298. // //#define RESULT_NET_ERROR -3
  1299. // //#define RESULT_NET_NOTAVAILABLE -4
  1300. // //#define RESULT_ERROR -5
  1301. // //#define RESULT_LOCALFILE_ERROR -7
  1302. // //#define RESULT_USERAUTH_ERROR -9
  1303. // //#define RESULT_UPDATE_USERAUTH_ERROR -11
  1304. // //#define RESULT_SESSION_EXPIRED -13
  1305. // //#define RESULT_VER_LOW
  1306. //
  1307. // // NSString * moreinfo = error.description ;
  1308. //
  1309. // NSString* err_msg = [error localizedDescription];
  1310. //
  1311. //
  1312. // //-----------------retry 3 times for error code -1005------------------------
  1313. // if(error.code==-1005&&retry<3)
  1314. // {
  1315. // retry++;
  1316. // goto repeat;
  1317. //
  1318. // }
  1319. // //-----------------end retry 3 times for error code -1005------------------------
  1320. //
  1321. // NSDictionary* error_json = [RAUtils error_dict:error];
  1322. // [ret setObject:error_json forKey:@"err_obj"];
  1323. // NSString* resp_msg= nil;
  1324. //
  1325. // if(err_msg.length==0)
  1326. // {
  1327. // err_msg =[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode];
  1328. // resp_msg = err_msg;
  1329. // }
  1330. // [ret setValue:[NSString stringWithFormat:@"%d",RESULT_NET_ERROR] forKey:@"result"];
  1331. // [ret setValue:err_msg forKey:@"err_msg"];
  1332. // [ret setValue:resp_msg forKey:@"resp_msg"];
  1333. // [ret setValue:[NSString stringWithFormat:@"%ld",(long)urlResponse.statusCode] forKey:@"resp_code"];
  1334. //
  1335. //
  1336. // NSData *jsonData = [NSJSONSerialization dataWithJSONObject:ret
  1337. // options:0
  1338. // error:nil];
  1339. // if(![url isEqualToString:recorder_url])
  1340. // {
  1341. // [self err_log:[RAUtils base64en:[RAConvertor dict2string:params]] result:[RAUtils base64en:[RAConvertor dict2string:ret]] module:url code:RESULT_NET_ERROR];
  1342. // }
  1343. // return jsonData;
  1344. //
  1345. // }
  1346. // else
  1347. // {
  1348. // // NSString* err_msg = [error localizedDescription];
  1349. // NSMutableString *str = [[NSMutableString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
  1350. //
  1351. // DebugLog(@"data string: %@",str);
  1352. // NSError *error1 = nil;
  1353. //
  1354. // NSMutableDictionary* jsobj = [[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error1] mutableCopy];
  1355. //
  1356. // if(jsobj==nil)// 服务器返回不是json
  1357. // {
  1358. //
  1359. // jsobj=[[NSMutableDictionary alloc] init];
  1360. // [jsobj setValue:[NSNumber numberWithInt:RESULT_NO_RESPONSE] forKey:@"result"];
  1361. //
  1362. // }
  1363. //// if([jsobj[@"encrypt"] boolValue]==true)
  1364. //// {
  1365. //// jsobj = decryptBlock(jsobj);
  1366. //// }
  1367. //// if (resultBlock) {
  1368. //// jsobj = resultBlock(jsobj);
  1369. //// }
  1370. //
  1371. // int result=[[jsobj valueForKey:@"result"] intValue];
  1372. // if(![url isEqualToString:recorder_url]&&/*![url isEqualToString:URL_DOWNLOAD_OFFLINE]&&*/result!=2&&result!=99)
  1373. // {
  1374. // [self err_log:[RAUtils base64en:[RAConvertor dict2string:params]] result:[RAUtils base64en:str] module:url code:result];
  1375. // }
  1376. // NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsobj
  1377. // options:0
  1378. // error:nil];
  1379. // return jsonData;
  1380. //
  1381. // }
  1382. // return responseData;
  1383. // }
  1384. }
  1385. @end