ios - AFNetworking 显示不支持的 URL 用于 http get 操作?

标签 ios objective-c afnetworking-2

现在我正在使用最新的 AFNetworking 库来执行 HTTP Get 操作,但我收到了不受支持的 URL 错误消息

但是当同样的时候,我在浏览器中点击我正在获取数据

https://abc.xyz.com/status?id={"request":["123"," 456"]}

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:BaseURLWithStatusInformation
      parameters:statusId
         success:^(AFHTTPRequestOperation *operation, id responseObject) {
             NSLog(@"JSON: %@", responseObject);
         } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
             NSLog(@"Error: %@", error);
         }];

所以这里的 BaseURLWithStatusInformation 是 https://abc.xyz.com/status?id=

statusId 是 {"request":["123","456"]} 即包含数组的字典。

最佳答案

看起来你的参数应该是:

@{@"id": @"{\"request\":[\"123\",\" 456\"]}"}

还有你的 BaseURLWithStatusInformation(大概现在叫做 BaseURL):

https://abc.xyz.com/status

因为您混合了查询字符串和 JSON。 AFNetworking 不会两者兼顾。我相信。

建议代码:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
id url = @"https://abc.xyz.com/status";
id params = @{@"id": @"{\"request\":[\"123\",\" 456\"]}"};
[manager GET:url parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

编辑:可能值得检查服务器实际需要什么,这种 JSON 和查询字符串格式的混合有点奇怪。可能您的参数应该改为:

@{@"id": @{@"request":@[@"123", @"456"]}}

关于ios - AFNetworking 显示不支持的 URL 用于 http get 操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29948264/

相关文章:

ios - 更改父(UIView)大小时布局不会更改

ios - PHAdjustmentData 大小限制

iphone - ios套接字流问题

iphone - 如何在 objective c 中使用 asin() 函数

iOS - 在 AFNetworking 异步图像下载线程完成后重新加载 UITableView

ios - 使用存储的 NSUserDefaults 登录网站

xcode - 尝试编译 AFNetworking 2.0 时架构 i386 的 undefined symbol

ios - 是否可以在 UITableView 中混合使用静态和动态原型(prototype)单元格?

objective-c - FilteredArrayUsingPredicate 总是返回 nil NSArray?

ios - self.dictionary 返回 null,即使它充满了键和值