我是第一次尝试这个并且我遇到了错误
Expected status code in (200-299), got 404
我正在关注本教程> link
我在下面创建了这个类:
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
来手动创建数据库和表(“登录”)。 / p>
我正在按照教程中的每一步操作,仍然会收到上述错误。另外,我手动将链接传递给浏览器“http:// localhost / Test /”并获得错误404。 我在这里缺少什么?
提前致谢。
答案 0 :(得分:0)
您传入的网址无效。在浏览器中检查URL ..
http//localhost/
或http://172.0.0.1/
或.. http://localhost:8080/
http://localhost/test/index.php
<强> UPD 强>
来自教程:
“解压缩的ZIP应该包含一些PHP文件和一个名为的文件夹 “上传。主要的API文件是index.php“
......然后......“
将Finder中的文件复制到您的网络文件夹“
...
“如果您有任何设置,则必须更改域和路径 除了从本地计算机调用API“
也许..你必须尝试http://localhost/xampp/test/
<强> UPD2 强>
错误403禁止访问:
<强> 1 强> a)在Finder中选择测试文件夹 b)选择“显示信息” c)在“所有权和权限”下,检查您是否已阅读\写入权限
<强> 2 强> 检查\修改你的httpd.conf从“拒绝所有”到“订单允许”和“允许所有人” - like here