【发布时间】:2011-06-19 17:22:16
【问题描述】:
当我通过 curl 调用时,有一个 JSON 调用,如下所示:
卷曲 -H “内容类型:应用程序/json”-H “接受:应用程序/json”-d "{\"checkin\":{\"message\":\"这是一个 测试\”}}” http://gentle-rain-302.heroku.com/checkins.json
我得到这个结果:
{"checkin":{"created_at":"2011-01-29T13:52:49Z","id":3,"message":"this 是一个 测试","updated_at":"2011-01-29T13:52:49Z"}}
但是当我像下面这样调用我的 iPhone 应用程序时:
- (void)doCheckIn:(NSString *)Str
{
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"inStore-settings.plist"];
NSDictionary *plistDictionary = [[NSDictionary dictionaryWithContentsOfFile:finalPath] retain];
NSString *appURL = [plistDictionary objectForKey:@"apiurl"];
appURL = [appURL stringByAppendingString:@"checkins.json"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:appURL]];
[request setPostValue:@"{\"checkin\":{\"message\":\"test\"}}" forKey:@"message"];
[request startSynchronous];
NSError *error = [request error];
if (!error) {
NSString *response = [request responseString];
NSLog(response);
}
}
我得到一个结果:
“您想要的更改被拒绝 (422)"
非常感谢任何帮助。
【问题讨论】:
-
appURL到底是什么值?另外,您确定您正确使用了 setPostValue: 方法吗?对我来说这似乎有点不对劲,因为您希望整个帖子正文为
{\"checkin\":{\"message\":\"test\"}}并且看起来您可能将其设置为message的值。 -
@raidfive:appURL 有“gentle-rain-302.heroku.com/checkins.json”,我什至试过:“[request setPostValue:@"This is a test message" forKey:@"message"];"没有任何效果!
标签: json ios asihttprequest