【问题标题】:How to send array contain dictionary to server using AFNetworking 2.0?如何使用 AFNetworking 2.0 将包含字典的数组发送到服务器?
【发布时间】:2015-05-06 15:03:39
【问题描述】:

我正在尝试使用 AFNetworking 2.0 使用 HTTP POST 操作,但我的网络服务出错。

我的邮政编码

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

    NSDictionary *parameters =myDictionary;
        [manager POST:[NSString getNewURLAsString:url] parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            NSLog(@"JSON: %@", responseObject);

            NSDictionary *dict = (NSDictionary *)responseObject;
            [[NSNotificationCenter defaultCenter] postNotificationName:AssignedToUserNotificationEvent object:dict];



        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"Error: %@", error);
        }];

现在我的输入 myDictionary 看起来像这样

{
    request =     {
        "assigned_by" = user1;
        "assigned_to" = "User 3";
        "assignment_remarks" = test;
        code = 01;
    };
}

错误日志

Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: bad gateway (502)" UserInfo=0x7fa9ddf05660 {NSUnderlyingError=0x7fa9dde91190 "Request failed: unacceptable content-type: text/html", com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7fa9dd9b3fb0> 

更新:

终于可以使用AFHTTPSessionManager解决问题

【问题讨论】:

    标签: ios objective-c iphone ios8 afnetworking-2


    【解决方案1】:

    您应该将 content-type 设置为 application/json。

    【讨论】:

    • 正确的 JSON 内容类型是 application/json。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多