-4

我有这个标准的 AFNetworking 方法

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

它总是失败。总是。

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

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

目前使用烧瓶我已经尝试 1. 返回用户的 JSON 表示 2. 返回 200 响应并且没有内容

这些似乎都不起作用。

我应该怎么办?

4

1 回答 1

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

于 2013-02-17T09:54:55.673 回答