2016-10-01 169 views
0

我想通過Afnetworking從服務器獲取json數據,但我得到一個錯誤。請求失敗:方法不允許(405)在Afnetworking

AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager]; 
manager.requestSerializer = [[AFJSONRequestSerializer alloc] init]; 
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"]; 

[manager POST:url parameters:0 success:^ void(AFHTTPRequestOperation * operationManager, id result) 
{ 

     NSLog(@"My Result Is :%@", result); 



} failure:^ void(AFHTTPRequestOperation * operationManger, NSError * error) 
{ 

NSLog(@"Error :%@", error.localizedDescription); 
}]; 
+1

這是一個服務器錯誤,那你爲什麼顯示的客戶端代碼? – Droppy

+0

其實Web服務在Android平臺上工作正常,但是當我嘗試在iOS中集成時,我得到了這個錯誤。 – arpit

+1

確定,然後顯示Android客戶端代碼。 – Droppy

回答

0
if ([[AFNetworkReachabilityManager sharedManager] isReachable]) { 
    //Add your request object to an AFHTTPRequestOperation 
     AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:urlRequest]; 

     operation.responseSerializer = [AFHTTPResponseSerializer serializer]; 

     [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation,id _responseObject) { 

      id responseObject = [ NSJSONSerialization JSONObjectWithData : _responseObject 
                    options : kNilOptions 
                    error : nil ] ; 


      NSLog(@"Response:%@",responseObject); 
      // Success ; 
      if(_success) 
      { 
       _success(responseObject) ; 

      } 

     } failure:^(AFHTTPRequestOperation *operation, NSError *error) { 
      NSLog(@"error: %@", [operation error]); 

      if(_failure) 
      { 
       _failure(error) ; 
      } 

     }]; 

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

    } 
    else 
    { 
     [Utility showInterNetConnectionMessage]; 

     NSError *error; 

     if(_failure) 
     { 
      _failure(error) ; 
     } 

    }