使用AFHTTPRequestOperation
变体AFHTTPClient
,如果您将用户名和密码作为参数发送,则将它们添加到 NSDictionary 中,如下所示并将它们作为参数发送,否则如果您想在正文中发送它们,您可以将它们作为 formData 发送。
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
[parameters setObject:username.text forKey:@"username"];
[parameters setObject:password.text forKey:@"password"];
AFHTTPClient *afHttpClient = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"http://yourbaseURL"]];
NSMutableURLRequest *request = [afHttpClient multipartFormRequestWithMethod:@"POST" path:@"/pathifAny" parameters:parameters constructingBodyWithBlock:^(id <AFMultipartFormData>formData)
{
// here you can send as body if you not setting as parameters
[formData appendPartWithFormData:[username.text dataUsingEncoding:NSUTF8StringEncoding] name:@"username"];
[formData appendPartWithFormData:[password.text dataUsingEncoding:NSUTF8StringEncoding] name:@"password"];
}];
AFHTTPRequestOperation *afHttpReqOperation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
这是关于 GET/POST 的简单教程