我已经使用 GET 很多次了。但在当前情况下,我必须使用使用 POST 方法的 webService。我已经阅读了许多教程,但无法做到。路径是“ http://vinipost.com/Services/Mobile_Application/wcfService.svc/logIn ”,参数是“id”和“pass”,用于测试的电子邮件ID是“shail@gmail.com”,密码是“夏尔”
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://vinipost.com/Services/Mobile_Application/wcfService.svc/logIn"]];
[httpClient setParameterEncoding:AFFormURLParameterEncoding];
NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path:@"http://vinipost.com/Services/Mobile_Application/wcfService.svc/logIn" parameters:@{@"id":@"shail@gmail.com",@"pass":@"shail"}];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
self.movies = [JSON objectForKey:@"logInResult"];
NSLog(@"=========%@",self.movies);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(@"Request Failed with Error: %@, %@", error, error.userInfo);
}];
[operation start];
输出
=========(
{
msg = "Server encountered error";
}
)
服务器端的人说它进入了 catch 块,这就是它打印“msg = 服务器遇到错误”的原因