Restkit如何设置响应参数?
代码如下:
- (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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
顶