gpt4 book ai didi

ios - 通过 Afnetworking 从 api 获取数据时出现问题

转载 作者:行者123 更新时间:2023-11-28 21:14:02 25 4
gpt4 key购买 nike

我正在使用 iOS Objective-c , AFNetworing 管理器 POST JSON数据这是我的代码,但没有给我数据。

我的代码:

NSString *strUrl2 = @"http://example.extension/admin/services/login.php";

NSMutableDictionary *dataDict = [[NSMutableDictionary alloc] init];
[dataDict setValue:@"dipesh@gmail.com" forKey:@"email"];
[dataDict setValue:@"123456" forKey:@"password"];

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [[AFJSONRequestSerializer alloc] init];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", @"application/json",@"application/x-www-form-urlencoded",@"png/jpg" , nil];

[manager POST:strUrl2
parameters:dataDict
success:^(AFHTTPRequestOperation* operation, id responseObject){

NSLog(@"Response: %@", responseObject);
}
failure:^(AFHTTPRequestOperation* operation, NSError* error){
NSLog(@"Error: %@", error);
// Releasing the semaphore to end the process from waiting state.

}];`

Not getting actual response.

获取响应:

{
login = {
message = "Please fill all required parameters";
status = failure;
};
}

注意:此 Web 服务适用于 postMan 和 android。

最佳答案

   NSString *strUrl2 = @"http://fitgritapp.com/admin/services/login.php";

NSMutableDictionary *dataDict = [[NSMutableDictionary alloc] init];
[dataDict setValue:@"dipesh@gmail.com" forKey:@"email"];
[dataDict setValue:@"123456" forKey:@"password"];


AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager POST:strUrl2 parameters:dataDict progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {

NSLog(@"%@",responseObject);

} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"%@",error);
}];

试试这个

login =     {
message = "";
status = success;
user = {
"created_on" = "2017-01-18 12:26:01";
email = "dipesh@gmail.com";
"facebook_id" = "";
"first_name" = Dipesh;
id = 4;
"is_active" = 1;
"last_name" = Sisodiya;
password = 123456;
"password_reset_token" = "";
"updated_on" = "0000-00-00 00:00:00";
};
};

关于ios - 通过 Afnetworking 从 api 获取数据时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41889285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com