这是我的第一次尝试,我正面临错误
Expected status code in (200-299), got 404
我正在关注本教程>链接
我已经创建了下面的类:
TalkToNetwork.h
#import "AFHTTPClient.h"
#import "AFNetworking.h"
typedef void (^JSONResponseBlock)(NSDictionary* json);
@interface TalkToNetwork : AFHTTPClient
@property (strong, nonatomic) NSDictionary* user;
-(BOOL)isAuthorized;
-(void)commandWithParams:(NSMutableDictionary*)params onCompletion:(JSONResponseBlock)completionBlock;
+(TalkToNetwork*)sharedInst;
@end
TalkToNetwork.m
#import "TalkToNetwork.h"
//the web location of the service
#define kAPIHost @"http://localhost/"
#define kAPIPath @"Test/"
@implementation TalkToNetwork
@synthesize user;
+(TalkToNetwork*)sharedInst{
static TalkToNetwork *sharedInstance = nil;
static dispatch_once_t oncePredicate;
dispatch_once(&oncePredicate, ^{
sharedInstance = [[self alloc] initWithBaseURL:[NSURL URLWithString:kAPIHost]];
});
return sharedInstance;
}
-(BOOL)isAuthorized{
return [[user objectForKey:@"IdUser"] intValue] > 0;
}
-(void)commandWithParams:(NSMutableDictionary*)params onCompletion:(JSONResponseBlock)completionBlock{
NSMutableURLRequest *apiRequest =
[self multipartFormRequestWithMethod:@"POST"
path:kAPIPath
parameters:params
constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
}];
AFJSONRequestOperation* operation = [[AFJSONRequestOperation alloc] initWithRequest: apiRequest];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
//success!
printf("success");
completionBlock(responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//failure :(
printf("failure");
completionBlock([NSDictionary dictionaryWithObject:[error localizedDescription] forKey:@"error"]);
}];
[operation start];
}
-(TalkToNetwork*)init{
self = [super init];
if (self != nil) {
user = nil;
[self registerHTTPOperationClass:[AFJSONRequestOperation class]];
[self setDefaultHeader:@"Accept" value:@"application/json"];
}
return self;
}
@end
我已经下载并安装了 XAMPP 作为教程建议,运行所有三个控件(Apache、MySQL、FTP),并且我已经使用phpmyadmin
它来手动创建数据库和表(“登录”)。
我正在按照教程中的每个步骤进行操作,但仍然出现上述错误。此外,我手动将链接传递给浏览器“http://localhost/Test/”并收到错误 404。我在这里缺少什么?
提前致谢。