美文网首页
iOS AFNetworking urlencoded

iOS AFNetworking urlencoded

作者: 彗星来的那一夜 | 来源:发表于2018-01-06 16:57 被阅读16次

    只需要加上:

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

    示例:

    NSString *url = [NSString stringWithFormat:@"%@%@",APIBASE,APIUSERENDPOINT];
    
    NSDictionary* parametersDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                              username, @"username",
                              password, @"password",
                              nil
                              ];
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc]initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
        [manager.requestSerializer setValue:@"application/x-www-form-urlencoded; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
        manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    
    [manager POST:url parameters:parametersDictionary progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"%@",responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@",error);
    }];
    

    相关文章

      网友评论

          本文标题:iOS AFNetworking urlencoded

          本文链接:https://www.haomeiwen.com/subject/kgiynxtx.html