我最近跟随CodeSchool 课程学习 iOS,他们推荐使用 AFNetworking 与服务器交互。
我正在尝试从我的服务器获取 JSON,但我需要将一些参数传递给 url。我不希望将这些参数添加到 URL,因为它们包含用户密码。
对于一个简单的 URL 请求,我有以下代码:
NSURL *url = [[NSURL alloc] initWithString:@"http://myserver.com/usersignin"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation
JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(@"%@",JSON);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(@"NSError: %@",error.localizedDescription);
}];
[operation start];
我检查了NSURLRequest的文档,但没有从那里得到任何有用的信息。
我应该如何将用户名和密码传递给该请求以在服务器中读取?