Get the location of iP and network operator
Applications used:7
Product services support payments in USD, HKD, and USDT
HTTP protocol:
http://api.youripapi.com/ipdata/
HTTPS protocol:
https://api.youripapi.com/ipdata/
* The API interface may be blocked due to various network reasons and attacks. Please make redundancy and exception handling during development
*If the status code returned by the HTTP request is not 200, perform an exception. For example, the status code 202 May be caused by invalid Token, insufficient balance, or incorrect format
P query interface example for Object-C(ios):
//
// ViewController.m
// ApiTest
//
// Created by administrator on 16/9/8.
// Copyright © 2016年 star. All rights reserved.
//
#import "ViewController.h"
#define Host @"https://api.youripapi.com/ip/"
@interface ViewController ()<NSXMLParserDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString * token = @"859476648b3de65d7680494506dd1a1c6a";
[self executeNetworkWithIP:@"8.8.8.8" dateType:@"xml" callBack:@"" token:token];
}
/**
* Example - https://api.youripapi.com/ip/?ip=8.8.8.8&datatype=jsonp&callback=&token=859476648b3de65d7680494506dd1a1c6a
* Parameter description:
* 1. iP string : iP address - eg. 117.25.13.123 (optional. The default value is the iP address of the requester)
* 2. datatype string : txt|jsonp|xml (optional. The default format is jsonp)
* 3. callback string : callback function - The current parameters are only available for jsonp format data (optional. The default value is empty)
* 4. token string : service will be provided after purchase (required)
*/
- (void)executeNetworkWithIP:(NSString *)ip dateType:(NSString *)dateType callBack:(NSString *)callBack token:(NSString *)token{
NSString * urlString =[NSString stringWithFormat:@"%@?ip=%@&datatype=%@&callback=%@&token=%@",Host,ip,dateType,callBack,token];
// Prepare the network request
NSString *newStr = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:newStr];
NSURLRequest *requst = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10];
// Request an asynchronous link
[NSURLConnection sendAsynchronousRequest:requst queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if (connectionError) {
NSLog(@"jsonError = %@",connectionError);
return ;
}
// Request format txt
if ([dateType isEqualToString:@"txt"]) {
NSString *result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"result = %@",result);
}
// datatype xml
else if ([dateType isEqualToString:@"xml"]){
NSString *result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"result = %@",result);
}
else{
NSError *jsonError = nil;
NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
/* If you set a callback function, you can intercept it and then convert it to NSDictionary, or you can convert it directly to NSString */
if (callBack&&[callBack length]>0) {
NSRange range = [jsonString rangeOfString:@"("];
range.location++;
range.length = [jsonString length] - range.location - 1;
jsonString = [jsonString substringWithRange:range ];
}
NSDictionary *jsonResponse =
[NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding]
options:0
error:&jsonError];
if (jsonError) {
NSLog(@"jsonError = %@",jsonError);
return ;
}
NSLog(@"jsonResponse = %@",jsonResponse);
}
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end