这是我尝试做的代码,它会返回未经授权的
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager setRequestSerializer:[AFJSONRequestSerializer serializer]];
[manager.requestSerializer setValue:@"application/json"forHTTPHeaderField:@"Content-Type"];
NSDictionary *parameters = @{@"user": @"name",@"email": @"a@gmail.com"};
[manager POST:@"http://testgcride.com:8081/v1/users" parameters:parameters
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
答案 0 :(得分:0)
The URL you're using需要用户名和密码才能访问。
它看起来像是HTTP基本身份验证,因此您应该能够获取凭据并进行设置:
[manager.requestSerializer setAuthorizationHeaderFieldWithUsername:@"username" password:@"password"];