我正在使用AFHTTPClient向Django+Tastypie应用程序发出请求。这个应用程序启用了APPEND_SLASH设置,这意味着如果网址不是以斜杠结尾,请求将被重定向到附加了斜杠的相同网址。
现在我正在做这件事:
[[AFHTTPClient sharedClient] getPath:@"entry" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"%@", error);
}];得到的URL是被重定向到http://www.example.com/api/v1/entry/的http://www.example.com/api/v1/entry。有没有办法告诉AFHTTPClient总是自动添加一个尾随斜杠?
发布于 2013-06-08 04:49:36
您需要执行以下任一操作
getPath:参数中提供尾随/ (如getPath:@"entry/"),或使用添加它的方法提供AFHTTPClient。下面是#2的一个例子:
- (void)getPath:(NSString *)path
parameters:(NSDictionary *)parameters
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
{
if ([path length] > 0 && ![path hasSuffix:@"/"])
path = [path stringByAppendingString:@"/"];
[super getPath:path parameters:parameters success:success failure:failure];
}https://stackoverflow.com/questions/16990745
复制相似问题