在afnetworking 3.0中发布请求?

时间:2016-06-08 13:08:05

标签: ios afnetworking afnetworking-3

我有一个应用程序,我正在使用Afnetnetworking3.0进行此类Web服务调用。

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

但是它在参数字典中添加了一些空格并且找不到URL。谁能告诉我哪里出错了?

1 个答案:

答案 0 :(得分:1)

试试这样:

   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
{


}

检查日志Sent parameter to server 1 ...并检查您的网址是否正确?