Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用PUT请求时发生AFN网络错误,错误为400_Ios_Ios5_Increment_Afnetworking_Put - Fatal编程技术网

Ios 使用PUT请求时发生AFN网络错误,错误为400

Ios 使用PUT请求时发生AFN网络错误,错误为400,ios,ios5,increment,afnetworking,put,Ios,Ios5,Increment,Afnetworking,Put,我正在尝试使用PUT请求增加解析数据 -(void)requestHit { AFHTTPClient *client = [[AFHTTPClient alloc]initWithBaseURL:[NSURL URLWithString:kHBFParseAPIBaseURLString]]; [client setDefaultHeader:@"X-Parse-Application-Id" value:kHBFParseAPIApplicationId]; [client set

我正在尝试使用PUT请求增加解析数据

-(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 -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

请帮助~~

默认情况下,AFHTTPClient将使用AFFormURLParameterEncoding作为参数编码方式,因此您必须将其设置为AFJSONParameterEncoding


某些java web服务器无法接收@_op:@1此类参数,您应该手动将其转换为@0或@1,这将避免400错误。试试看。

失败的错误域=com.alamofire.networking.Error Code=-1011 200-299中的预期状态代码,获得400 UserInfo=0x6b9edd0{nserrorfailingurkey=,NSLocalizedDescription=200-299中的预期状态代码,获得400}