x-www-form-urlencoded objective c

时间:2016-11-08 12:18:36

标签: ios objective-c iphone api

我正在尝试连接到Api,但它正在使用x-www-form-urlencoded ......我正在使用此代码.Plz告诉我正确的方法

AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
securityPolicy.allowInvalidCertificates = YES;


AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer.acceptableContentTypes = nil;
manager.securityPolicy = securityPolicy;

[manager POST:[NSString stringWithFormat:@"@"%@%@phone=%@&password=%@",BASE_URL,API_LOGIN,phone,password]
   parameters:nil
      success:^(AFHTTPRequestOperation *operation, id responseObject) {

          successBlock(responseObject);

      } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

          NSLog(@"Server Error : %@", operation.responseString);
          errorBlock(error);
      }];

}

1 个答案:

答案 0 :(得分:1)

我认为您应该尝试为' x-www-form-urlencoded'设置http标头。与你的后端沟通:

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

如果这不能解决您的错误,请尝试验证您的json对象。
您还可以查看此问题:AFNetworking 3 x-www-form-urlencoded post data