我正在使用AFNetworking
与服务器进行交互。
在 postman 中,我成功 成功,但使用AFnetworking
获取错误:
status code: 500, headers
"Cache-Control" = "no-cache";
Connection = close;
"Content-Type" = "application/json";
Date = "Tue, 24 Jan 2017 06:39:01 GMT";
Server = "Apache/2.4.7 (Ubuntu)";
以下是我的参考代码:
AFNetworkReachabilityManager *reachabilityManager = [AFNetworkReachabilityManager sharedManager];
if(![reachabilityManager isReachable])
{
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"" message:@"Network not available." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
return;
}
[self.view setUserInteractionEnabled:NO];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSLog(@"userid:%@",[userDefaults valueForKey:@"user_id"]);
NSDictionary *dict = [[NSDictionary alloc]initWithObjectsAndKeys:@"5",@"customer_id",@"5885e8968fa4293d182ad0a1",@"id[]",nil]; //2
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];
NSString *str =@"http://xxx/yyy/customer/";
NSString *strURl = [NSString stringWithFormat:@"%@assets/deleteElement",str];
NSLog(@"url:%@\n %@",strURl,dict);
[APP_DELEGATE showLoading:self];
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict
options:NSJSONWritingPrettyPrinted
error:&error];
if (! jsonData) {
NSLog(@"Got an error: %@", error);
} else {
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSLog(@"json:%@",jsonString);
}
[manager POST:strURl parameters:dict progress:nil success:^(NSURLSessionTask *task, id responseObject)
{
NSLog(@"response: %@", responseObject);
[self.view setUserInteractionEnabled:YES];
dispatch_async(dispatch_get_main_queue(), ^{
[APP_DELEGATE removeLoading];
});
} failure:^(NSURLSessionTask *operation, NSError *error)
{
NSLog(@"Error: %@", error.debugDescription);
}];
有任何帮助来解决这个问题吗?
答案 0 :(得分:1)
404未找到文件。如果api是post或get,则重新检查或者你应该只检查这个2。
NSString *str =@"http://api.beyondchange.in/api/customer/";
NSString *strURl = [NSString stringWithFormat:@"%@/assets/deleteElement",str];
OR
manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];