我在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);
}];