2013-02-23 93 views
1

我的代码:AFNetworking错误:“预期状态码(200-299),获得404”

NSURL *url = [NSURL URLWithString:@"http:testurl.com"]; 
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url]; 

NSString *email = @"[email protected]"; 
NSString *password = @"test"; 

NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys: 
         email, @"email", 
         password, @"password", 
         nil]; 

[httpClient postPath:@"/myobject" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) { 
    NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:AFJSONParameterEncoding]; 
    NSLog(@"Request Successful, response '%@'", responseStr); 
} failure:^(AFHTTPRequestOperation *operation, NSError *error) { 
    NSLog(@"[HTTPClient Error]: %@", error.localizedDescription); 
}]; 

即使我知道服务器是预期POST我试图获取和放置过,仍然收到同样的错误。我也检查了100次URL。任何想法是什么导致了错误?

谢谢!

回答

2

转到URL通过把http:testurl.com/myobject一起在浏览器中取得。 404意味着页面或资源不存在。

尝试也正斜杠到的baseUrl,即以基本URL和http://testurl.com/到postPath看到myobjectthis issue

+0

那样简单的建议是,是我需要什么谢谢! – markw 2013-02-23 13:40:01

1

您的基本网址的格式不正确。

更改此:"http:testurl.com"

为了这个:"http://testurl.com"

+1

对不起我的实际代码有“HTTP://”我躲在草率的网址 – markw 2013-02-23 13:35:21