0

我想用 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 = {“状态”:假,“错误”:“未知方法。”}

4

0 回答 0