0
這裏發送JSON數據的代碼是我嘗試做的,它返回未經授權IOS如何使用HTTP POST請求
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager setRequestSerializer:[AFJSONRequestSerializer serializer]];
[manager.requestSerializer setValue:@"application/json"forHTTPHeaderField:@"Content-Type"];
NSDictionary *parameters = @{@"user": @"name",@"email": @"[email protected]"};
[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);
}];
我猜你調用的API testgcride需要某種授權頭的要與請求一起發送? –