我正在使用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.
}];`
没有得到实际回复。
获得回复:
{
login = {
message = "Please fill all required parameters";
status = failure;
};
}
注意: 这个web服务在postMan和android上工作。
答案 0 :(得分:2)
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";
};
};