AFNetworking - 卷曲工作 - AFNetworking代码没有 - 这有什么不对吗?

时间:2018-06-09 21:20:20

标签: afnetworking-3

我在CURL中有以下内容,它有效!

curl -X POST -H 'Cache-Control: no-cache' -H 'Content-Type: multipart/form-data' -F 'grant_type=password' -F 'username=<api_username>' -F 'password=<api_password>' -F 'client_id=affiliated-api' 'https://getsometoken.com/token'

那么为什么Obj-C中的以下内容不起作用?我收到请求失败:错误请求(400)&#39;

这是我的代码..任何想法?提前谢谢!

 AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc]init];

    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    [manager.requestSerializer setValue:@"application/x-www-form-urlencoded; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];



    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"application/json"];


    NSDictionary* paramsDict = [NSDictionary dictionaryWithObjectsAndKeys:
                                          @"password", @"grant_type",
                                          @"somename", @"username",
                                          @"xxxxxx", @"password",
                                          @"client1", @"client_id", nil];


    NSString *completeURL= [NSString stringWithFormat:@"https://getsometoken.com/token"];

    [manager POST:completeURL parameters:paramsDict success:^(NSURLSessionDataTask *task, id responseObject){
         NSLog(@"Response%@",responseObject);

         if ([[NSString stringWithFormat:@"%@",[responseObject valueForKey:@"status"]] isEqualToString:@"1"])
         {
             NSDictionary *data = (NSDictionary *)responseObject;
             NSLog(@"OAuth token data - %@",data);
         }
         else
         {
             NSLog(@"Not response");
         }
     }
        failure:^(NSURLSessionDataTask *task, NSError *error)
        {
         NSLog(@"Failure Errror ", error);

       }];

0 个答案:

没有答案