我在项目中使用“ restkit 0.20.3”,

由于一些至关重要的原因,我将把所有的API调用转换为ret套件,

请任何人告诉我,我该如何打电话给下面的休息套件,我要发送我的 ASIHHTP 代码请任何人都可以将其迁移到休息套件,我找不到方法

NSDictionary *dictionary=....;

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@auth/login",KBASEURL]];


ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];


[request setRequestMethod:@"POST"];


[request setValidatesSecureCertificate:NO];


[request addRequestHeader:@"Content-Type" value:@"application/json; charset=utf-8"];


 NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dataDictionary options:kNilOptions error:nil];

[request setPostBody:(NSMutableData *)jsonData];

[request setContentLength:[jsonData length]];
有帮助吗?

解决方案

RKObjectManager *manager =  [RKObjectManager managerWithBaseURL:[NSURL URLWithString:@"https://172.22.221.117/api/v1.0/"]];

 NSDictionary *dictionary=[NSDictionary dictionaryWithObjectsAndKeys:@"abc.com",@"email",@"password",@"password", nil];

[manager postObject:nil
               path:@"auth/login"
         parameters:dictionary
            success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {


            }
            failure:^(RKObjectRequestOperation *operation, NSError *error) {
                NSLog(@"Error: %@", error);
                if(operation.HTTPRequestOperation.response.statusCode==200){
                    //do your processing
                }
            }];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top