#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
// 定義請(qǐng)求的基礎(chǔ)信息
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"; // 請(qǐng)?zhí)鎿Q為您的鑒權(quán)簽名
// 定義請(qǐng)求的數(shù)據(jù)
NSMutableDictionary *values = [NSMutableDictionary dictionaryWithDictionary:@{
@"mobiles": @[@"18800000000", @"18800000001"], //手機(jī)號(hào)數(shù)組(最多10個(gè))
}];
// 將數(shù)據(jù)轉(zhuǎn)換為JSON數(shù)據(jù)
NSError *error = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:values
options:0
error:&error];
if (error) {
NSLog(@"JSON序列化錯(cuò)誤: %@", error.localizedDescription);
return 1;
}
// 創(chuàng)建請(qǐng)求對(duì)象
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:30.0];
// 設(shè)置請(qǐng)求方法和頭部
[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"];
// 設(shè)置請(qǐng)求體
[request setHTTPBody:jsonData];
// 創(chuàng)建會(huì)話(huà)和任務(wù)
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (error) {
NSLog(@"請(qǐng)求錯(cuò)誤: %@", error.localizedDescription);
return;
}
// 處理響應(yīng)
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
NSLog(@"狀態(tài)碼: %ld", (long)httpResponse.statusCode);
if (data) {
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"響應(yīng)內(nèi)容: %@", responseString);
}
}];
[task resume];
// 保持程序運(yùn)行直到請(qǐng)求完成(僅用于測(cè)試)
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:5.0]];
}
return 0;
}
國(guó)內(nèi)專(zhuān)業(yè)互聯(lián)網(wǎng)團(tuán)隊(duì)
21年行業(yè)經(jīng)驗(yàn)
7x24小時(shí)售后支持
豐富的行業(yè)經(jīng)驗(yàn)
互 億 無(wú) 線(xiàn) 官 方 微 信 號(hào)
Copyright ? 2004-2025 上海思銳信息技術(shù)有限公司 All rights reserved. 滬ICP備07035915號(hào)-15 電信增值業(yè)務(wù)許可證:B2-20160082
服務(wù)熱線(xiàn):
4008 808 898
服務(wù)熱線(xiàn)(工作時(shí)間):
4008 808 898
業(yè)務(wù)咨詢(xún)(非工作時(shí)間):
售后咨詢(xún)(非工作時(shí)間):