Restkit如何设置响应参数?

发布于 2021-11-25 00:43:21 字数 3490 浏览 961 评论 1

代码如下:

- (void) submitOrder:(id) order
             success:(void (^)()) success
             failure:(void (^)(NSError *error))failure {
    
    RKObjectMapping *requestMapping = [RKObjectMapping requestMapping];
    [requestMapping addAttributeMappingsFromArray:@[@"userId", 
                                                    @"serviceType",
                                                    @"orderInfo"]];
    
    RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:requestMapping objectClass:[LMOrder class] rootKeyPath:nil method:RKRequestMethodAny];
    
//    RKObjectMapping *resultMapping = [RKObjectMapping mappingForClass:[NSString class]];
//    NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);
//    RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:resultMapping method:RKRequestMethodPOST pathPattern:nil keyPath:nil statusCodes:statusCodes];
 
    RKObjectManager* manager = [RKObjectManager sharedManager];
    [manager addRequestDescriptor:requestDescriptor];
//    [manager addResponseDescriptor:responseDescriptor];
    
    [manager setAcceptHeaderWithMIMEType: RKMIMETypeJSON];
    [manager setRequestSerializationMIMEType:RKMIMETypeJSON];

    [manager postObject:order path:@"OrderService/submitOrder" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
        success();
    } failure:^(RKObjectRequestOperation *operation, NSError *error) {
        failure(error);
    }];
}

返回如下错误:

javax.servlet.ServletException: org.springframework.web.client.ResourceAccessException: I/O error: Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect

AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest: 0xb79fae0> { URL: http://172.16.0.106:9090/rest/OrderService/submitOrder }, NSErrorFailingURLKey=http://172.16.0.106:9090/rest/OrderService/submitOrder, NSLocalizedDescription=Expected status code in (200-299), got 500, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0xb7487f0> { URL: http://172.16.0.106:9090/rest/OrderService/submitOrder } { status code: 500, headers {
    Connection = close;
    "Content-Encoding" = gzip;
    "Content-Type" = "text/html;charset=utf-8";
    Date = "Mon, 20 Jan 2014 10:08:49 GMT";
    Server = "Apache-Coyote/1.1";
    "Transfer-Encoding" = Identity;
    Vary = "Accept-Encoding";
} }}
(lldb) 

可以确认的是,服务端已经接收到请求并调用了业务层代码,但服务端返回响应失败。服务端代码返回的是一个表示成功或者失败的代码字符串“SUCCESS”,“ERROR”,那我RestKit请求的响应格式要如何设置才能正确Post请求呢??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉生梦死 2021-11-25 23:04:57

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文