【问题标题】:AFNetworking Always Fails [closed]AFNetworking 总是失败 [关闭]
【发布时间】:2013-02-17 08:36:33
【问题描述】:

我有这个标准的 AFNetworking 方法

[self postPath:@"/signup/" 参数:params 成功:^(AFHTTPRequestOperation *operation, id responseObject)

它总是失败。总是。

我需要做什么才能让它通过。后端服务器应该向应用返回什么才能通过?

如果你不熟悉 Python,最好是 Flask/Django,或者只是解释一下这个概念

目前使用烧瓶 我试过了 1. 返回用户的 JSON 表示 2. 返回 200 响应且无内容

这些似乎都不起作用。

我该怎么办?

【问题讨论】:

  • 这和your other question有什么不同?
  • 类似,我只是把它分解成一个更小的部分,因为没有人回答完整的问题,我认为这可能更容易回答。
  • 如果您想要更好的答案,您应该尽可能详细地解释“它总是失败”的含义。 (你有没有得到响应?如果有,里面有什么?有错误代码吗?你确定你在和你的服务器通话,如果有,它发回了什么数据?你有什么错误吗?服务器中的日志?等等)

标签: iphone ios objective-c ipad afnetworking


【解决方案1】:

这是我的一个旧项目(AFNetworking 和 JSON 响应)中的一个工作示例:

- (void) loadItems:(NSString*)searchText
{
    NSString *surl = [NSString stringWithFormat:@"http://localhost:8888/index.php?s=%@", searchText];
    NSURL *url = [NSURL URLWithString:surl];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];

    [AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/html"]]; //content-type is not set properly by the server
    AFJSONRequestOperation *operation =
        [AFJSONRequestOperation JSONRequestOperationWithRequest:request
            success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
                NSLog(@"Done: %@", JSON);                
            }
            failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON){
                NSLog(@"failure: %@", [error description]);
            }];

    [operation start];
}

希望这会有所帮助。

您还可以检查 POST 请求的此答案: AFNetworking - How to make POST request

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多