使用AFNetworking的PUT方法

时间:2013-02-25 09:08:04

标签: ios networking afnetworking nsurlrequest put

我想用put请求实现afnetworking,但是当我运行它时它总是显示错误。 使用post方法可以正常工作,但是当我将其更改为PUT时,它会显示错误。

AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:urls];
    [httpClient defaultValueForHeader:@"Accept"];

    NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                            @"345", @"page_id",
                            @"john",@"username",
                            nil];

    NSMutableURLRequest *request = [httpClient requestWithMethod:@"PUT"
                                                            path:@""
                                                      parameters:params];



    //Add your request object to an AFHTTPRequestOperation
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]
initWithRequest:request];



    [httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];

    [operation setCompletionBlockWithSuccess:
     ^(AFHTTPRequestOperation *operation,
       id responseObject) {
         NSString *response = [operation responseString];
         NSLog(@"response: [%@]",response);
     } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
         NSLog(@"error: %@", [operation error]);
     }];

    //call start on your request operation
    [operation start];

错误说:

错误域= AFNetworkingErrorDomain代码= -1011“(200-299)中的预期状态代码,得到404”UserInfo = 0x75a9d40 {NSLocalizedRecoverySuggestion = {“status”:false,“error”:“Unknown method。”}

0 个答案:

没有答案