本文為您提供了Objective-C語言版本的提交查詢接口對(duì)接DEMO示例
#import <Foundation/Foundation.h>
// 簡單的HTTP POST請(qǐng)求示例
void sendSimplePostRequest() {
// 創(chuàng)建URL
NSURL *url = [NSURL URLWithString:@"https://api.ihuyi.com/ocr/cnpassport/Submit.json"];
// 創(chuàng)建請(qǐng)求
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
// 準(zhǔn)備表單數(shù)據(jù)
NSString *postString = @"account=xxxxxxxx&password=xxxxxxxxx&img_file=&img_url=&time=1623643787&";
NSData *postData = [postString dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:postData];
// 發(fā)送請(qǐng)求
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"錯(cuò)誤: %@", error.localizedDescription);
return;
}
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"響應(yīng): %@", responseString);
}];
[task resume];
}
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSLog(@"發(fā)送請(qǐng)求...");
sendSimplePostRequest();
// 等待請(qǐng)求完成
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:3]];
}
return 0;
}
國內(nèi)專業(yè)互聯(lián)網(wǎng)團(tuán)隊(duì)
21年行業(yè)經(jīng)驗(yàn)
7x24小時(shí)售后支持
豐富的行業(yè)經(jīng)驗(yàn)
互 億 無 線 官 方 微 信 號(hào)
Copyright ? 2004-2025 上海思銳信息技術(shù)有限公司 All rights reserved. 滬ICP備07035915號(hào)-15 電信增值業(yè)務(wù)許可證:B2-20160082
服務(wù)熱線:
4008 808 898
服務(wù)熱線(工作時(shí)間):
4008 808 898
業(yè)務(wù)咨詢(非工作時(shí)間):
售后咨詢(非工作時(shí)間):