IOS-GET request details-GET sets the Request Header
A rare remark is a very detailed native GET network request operation, which is recorded as obsessive-compulsive disorder and shared with you... Also used for backup Replication
-(Void) getResult {_ MB = [MBProgressHUD showHUDAddedTo: self. navigationController. view animated: YES]; // interface path NSString * path = @ "http://a.apix.cn/apixlife/phone/phone"; // path-+ parameter NSString * pathWithPhoneNum = [NSString stringWithFormat: @ "% @? Phone = % @ ", path, _ phoneNumFD. text]; // Chinese encoded NSString * urlPath = [pathWithPhoneNum character: [NSCharacterSet URLQueryAllowedCharacterSet]; // url nsurl * phoneURL = [NSURL URLWithString: urlPath]; // request object NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL: phoneURL]; // request method [request setHTTPMethod: @ "GET"]; // request Header [request setValue: @ "92b5787ecd1720.b718 Activities "activities: @" apix-key "]; // network configuration NSURLSessionConfiguration * configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; // Network session NSURLSession * session = [NSURLSession sessionWithConfiguration: configuration]; // task NSURLSessionDataTask * sessionTask = [session dataTaskWithRequest: request completionHandler: ^ (NSData * _ Nullable data, NSURLResponse * _ Nullable response, NSError * _ Nullable error) {// return to the main thread to update the UI-> cancel the mask dispatch_async (dispatch_get_main_queue (), ^ {[_ MB hide: YES];}); if (error) {NSLog (@ "request failed... % @ ", error); // prompt that the user request failed! UIAlertController * AV = [UIAlertController alertControllerWithTitle: @ "prompt" message: @ "sorry, server error. Please try again later... "preferredStyle: Regular]; [AV addAction: [UIAlertAction actionWithTitle: @" OK "style: UIAlertActionStyleDefault handler: ^ (UIAlertAction * _ Nonnull action) {// click OK, you can set nil NSLog (@ "you clicked OK .. ") ;}]]; [self presentViewController: AV animated: YES completion: nil];} else {// JSON parses Apple's native most efficient NSDictionary * result = [NSJSONSerialization JSONObjectWithData: data options: NSJSONReadingMutableLeaves error: nil]; if ([result objectForKey: @ "message"] isEqualToString: @ "success"]) {// get data-> the main thread updates the UI dispatch_async (dispatch_get_main_queue (), ^ {NSDictionary * data = [result objectForKey: @ "data"]; NSString * city = [data objectForKey: @ "city"]; NSString * province = [data objectForKey: @ "province"]; NSString * belong = [NSString stringWithFormat: @ "% @ · % @", province, city]; [_ resultLB setText: belong] ;}) ;}else {NSLog (@ "No information found .... ");} NSLog (@" request successful... % @ ", result) ;}}]; // start the task [sessionTask resume];}