hacker
hacker

Reputation: 8957

Post request in afnetworking 3.0?

I had an application in which I am using Afnetnetworking3.0 for web service calls like this.

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager setRequestSerializer:[AFJSONRequestSerializer serializer]];
[manager setResponseSerializer:[AFJSONResponseSerializer serializer]];

NSURL * urlStr = [NSURL URLWithString:path];

NSDictionary *parameters = @{@"ID":@"fdfdfd",@"No":@"1414"};
NSLog(@"%@",parameters);

[manager POST:urlStr.absoluteString 
   parameters:parameters 
     progress:nil 
      success:^(NSURLSessionDataTask *task, id responseObject) {

                                NSLog(@"JSON: %@", responseObject);

                            } failure:^(NSURLSessionDataTask *task, NSError *error) {

                                NSLog(@"Error: %@", error);
                            }];

But it is adding some spaces in parameters dictionary and making the URL not found. Can anybody tell me where I am going wrong ?

Upvotes: 0

Views: 3378

Answers (1)

TheHungryCub
TheHungryCub

Reputation: 1970

Try like this :

   NSString *Loginurl = [NSString stringWithFormat:@"http://Enter your url here"];


    NSDictionary *params = @{
                             @"ID":@"fdfdfd",
                             @"No":@"1414"
                             };

    NSLog(@"Sent parameter to server 1 : %@",params);
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];

    manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];

    manager.responseSerializer = [AFHTTPResponseSerializer serializer];

    AFSecurityPolicy* policy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];

    [policy setValidatesDomainName:NO];

    [policy setAllowInvalidCertificates:YES];

    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];

    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/html",nil];

    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/plain",nil];



    [manager POST:Loginurl parameters:params progress:nil success:^(NSURLSessionTask *task, id responseObject) {


        NSLog(@"Response from server 1 :  %@", [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]);

        [self getdata:responseObject];


    }
          failure:^(NSURLSessionTask *operation, NSError *error)

     {

         NSLog(@"Error: %@", error);

 }];    
}


-(void)getdata:(NSDictionary*)RegisterData
{


}

check the log Sent parameter to server 1... and check your url is correct or not?

Upvotes: 1

Related Questions