我正试图提出PPOST请求,要求REST AP张贴新的入境时间。 员额请求所需的XML结构如下:
<time-entry>
<person-id>#{person-id}</person-id>
<date>#{date}</date>
<hours>#{hours}</hours>
<description>#{description}</description>
</time-entry>
有了AFNetworking,XML在幕后进行编码,从通过一个参数的NSDictionary到POST的要求? 我的法典是:
我的APIClient:
-(void)postTimeEntry:(TLActiveWork *)work {
[self setAuthorizationHeaderWithUsername:[self.activeUser username]
password:[self.activeUser password]];
// Most of the following is static data. Just trying to get a successful POST at the
// moment.
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat:@"%@",[[self activeUser] personId]], @"person-id",
[NSString stringWithFormat:@"%@",[NSDate date]], @"date",
@"1", @"hours",
@"testing...!", @"description",
nil];
NSDictionary *wrapper = [NSDictionary dictionaryWithObjectsAndKeys:
params, @"time-entry",
nil];
NSLog(@"Params: %@", wrapper);
// AFNetworking call!
[self postPath:[NSString stringWithFormat:@"/projects/%@/time_entries.xml",
[[work project] projectId]] parameters:wrapper
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"-----SUCCESS!!!-----");
} failure:^(__unused AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"failure: %ld - %@", [operation.response statusCode],
[error description]);
}];
}
是的。 我的APIClient行动(s)通过:
[self registerHTTPOperationClass:[AFXMLRequestOperation class]];
我现在每次尝试采用该守则时,我总是收到422份回复守则的失败,我认为这意味着通过的实体是无法处理的。 https://stackoverflow.com/a/3291292/312411
我认为,我的问题是,通过“NSDictionary params”的论点正确建立该员额的XML吗?
任何帮助都值得赞赏。
感谢。