#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
// 定义请求的基础信息
NSString *host = @"api.ihuyi.com";
NSString *path = @"/empty-number/submit";
NSString *urlString = [NSString stringWithFormat:@"http://%@%@", host, path];
NSURL *url = [NSURL URLWithString:urlString];
// 定义signature变量
NSString *signature = @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; // 请替换为您的鉴权签名
// 定义请求的数据
NSMutableDictionary *values = [NSMutableDictionary dictionaryWithDictionary:@{
@"mobiles": @[@"18800000000", @"18800000001"], //手机号数组(最多10个)
}];
// 将数据转换为JSON数据
NSError *error = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:values
options:0
error:&error];
if (error) {
NSLog(@"JSON序列化错误: %@", error.localizedDescription);
return 1;
}
// 创建请求对象
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:30.0];
// 设置请求方法和头部
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"Tue, 26 Aug 2025 07:14:23 GMT" forHTTPHeaderField:@"Date"];
[request setValue:[NSString stringWithFormat:@"Signature %@" , signature] forHTTPHeaderField:@"Authorization"];
// 设置请求体
[request setHTTPBody:jsonData];
// 创建会话和任务
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (error) {
NSLog(@"请求错误: %@", error.localizedDescription);
return;
}
// 处理响应
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
NSLog(@"状态码: %ld", (long)httpResponse.statusCode);
if (data) {
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"响应内容: %@", responseString);
}
}];
[task resume];
// 保持程序运行直到请求完成(仅用于测试)
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:5.0]];
}
return 0;
}
在线咨询
150,000家
企业客户
21年
行业经验
2V1
2对1客户支持