Is my first attempt on this and I am facing the error
Expected status code in (200-299), got 404
I am following this tutorial > link
and I have create the class below:
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
I have downloaded and installed XAMPP as tutorial advice, running all three Controls (Apache, MySQL, FTP) and I have used phpmyadmin in order to create the database and a table (“login”) manually.
I am following each step from the tutorial and still getting the error above. In addition, I’m passing manually the link to the browser “http://localhost/Test/” and getting Error 404.
What I am missing here?
Thanks in advance.
You’re passing in a URL that is not valid. Check in your browser the URL ..
http//localhost/orhttp://172.0.0.1/or..http://localhost:8080/http://localhost/test/index.phpUPD
from tutorial:
… then.. “
…
Perhaps.. you must try
http://localhost/xampp/test/UPD2
Error 403 Access Forbidden:
1
a) In Finder select test folder
b) Choose ‘Show info’
c) Under “Ownership & Permissions” check to have you read\write permission
2
check\modify your httpd.conf from “Deny from all” to “Order allow” and “Allow from all” – like here