我已经开始使用AFNetworking,它可以很好地进行简单的"GET"请求.但是现在我正在尝试进行"POST" - 请求.我使用下面的代码来执行"GET"请求.在查看AFHTTPClient的puthPath时,无法设置要用于正文的数据.我的猜测是,有另一种解决方法.我一直在关注AFHTTPOperation作为解决这个问题的方法.但是,我没有让这个工作.问题是我不知道如何在基本身份验证中使用它.
有人可以给我一个如何用AFNetworking做一个简单的"POST"请求的提示吗?
AFHTTPClient* client = [AFHTTPClient clientWithBaseURL:ServerURL];
[client setAuthorizationHeaderWithUsername:self.username
password:self.password];
NSString* resourcePath = [NSString stringWithFormat:@"/some/resource/%@",
endPath];
[client getPath:resourcePath
parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject) {
// Success code omitted
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// Some error handling code omitted
}
];
Run Code Online (Sandbox Code Playgroud)