我正在尝试使用 PUT 请求增加 Parse 上的数据。
-(void)requestHit {
AFHTTPClient *client = [[AFHTTPClient alloc]initWithBaseURL:[NSURL URLWithString:kHBFParseAPIBaseURLString]];
[client setDefaultHeader:@"X-Parse-Application-Id" value:kHBFParseAPIApplicationId];
[client setDefaultHeader:@"X-Parse-REST-API-Key" value:kHBFParseAPIKey];
[client registerHTTPOperationClass:[AFJSONRequestOperation class]];
NSDictionary *jsonDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
@"Increment",@"__op", [NSNumber numberWithInt:100],@"amount",
nil];
NSError *error = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDictionary options:0 error:&error];
if (!jsonData) {
NSLog(@"NSJSONSerialization failed %@", error);
}
NSString *json = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
NSDictionary * params = [[NSDictionary alloc]initWithObjectsAndKeys: json, @"hot", nil];
[client putPath:self.shopping.objectId parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject){
NSLog(@"Success %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Failed %@", error);
}];
}
我收到错误代码 400。我知道 400 表示 URL 错误,但我在 safari 上检查了 URL,并且能够访问该网站。我在想也许字典编码错误但不知道。这是 Parse 网站上增量的 REST API cURL:
curl -X PUT \
-H "X-Parse-Application-Id: DWZFxindnjGtp3SCMmA4iGaYN55dgVDRmobt7mkC" \
-H "X-Parse-REST-API-Key: QbjhRMhVshPkJmEoDdpS3xAkNOofzLsUBlMBQETU" \
-H "Content-Type: application/json" \
-d '{"score":{"__op":"Increment","amount":1}}' \
https://api.parse.com/1/classes/GameScore/Ed1nuqPvcm
请帮忙~~