【发布时间】:2014-10-21 12:40:15
【问题描述】:
我有一个我想要实现的 put 请求。我遇到的问题是它没有将正确的原始正文发送到服务器表单/发布参数。我期待的是{"questions":[{"type":"control_head"}]} 的原始正文,而不是我得到questions[][type]=control_head 任何提示或建议表示赞赏。
NSString *jsonString = @"{\"questions\":[{\"type\":\"control_head\"}]}";
[self createForms:jsonString];
- (void) createForms : (NSString *) form
{
[self executePutRequest:@"user/forms" params:form];
}
- (void) executePutRequest : (NSString *) url params : (NSString *) params
{
NSString *urlStr = [NSString stringWithFormat:@"http://requestb.in/13oujhot"];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSData *data = [params dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSMutableDictionary *userinfo = [[NSMutableDictionary alloc] init];
[manager PUT:urlStr parameters:json success:^(AFHTTPRequestOperation *operation, id responseObject) {
[operation setUserInfo:userinfo];
SBJsonParser *jsonparser = [SBJsonParser new];
id result = [jsonparser objectWithString:[operation responseString]];
if ( self.delegate != nil && [self.delegate respondsToSelector:finishSelector] ) {
[self.delegate performSelector:finishSelector withObject:result];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[operation setUserInfo:userinfo];
if ( self.delegate != nil && [self.delegate respondsToSelector:failSelector] ) {
[self.delegate performSelector:failSelector withObject:[operation error]];
}
}];
}
【问题讨论】:
-
你是
NSJSONSerialization数据已经是JSON。
标签: ios iphone http afnetworking put