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];

エラーは言う:

エラー Domain=AFNetworkingErrorDomain Code=-1011 "Expected status code in (200-299), got 404" UserInfo=0x75a9d40 {NSLocalizedRecoverySuggestion={"status":false,"error":"Unknown method."}

4

0 に答える 0