2013-11-04 1 views
0

iOS 프로젝트에서 웹 서비스를 사용하려고합니다. 나는 그것을 위해 AFNetworking을 사용합니다. 그러나 현재 버전은 2.x에서이다 그러나 나는 1.x의 버전 만 예제 코드를 발견 : 'AFHTTPRequestOperation'AFNetworking 2를 사용하는 웹 서비스를 사용합니다.

I를 내가 'AFHTTPRequestOperationManager'에서 'AFHTTPClient을'변환하는 방법을 모르는

- (IBAction)loginButtonPressed {   
    NSURL *baseURL = [NSURL URLWithString:@"https://localhost/ws/"]; 


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

    NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys: 
          @"tester", "nameField", 
          nil]; 

    NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" 
      path:@"https://localhost/ws/hello" parameters:params]; 

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

    [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]; 
    [httpClient release]; 
} 

또는 그러나 2 일 동안 인터넷 검색을 시도했지만 사용할 수있는 결과가 없습니다.

서비스는 'name'을 수신하고 'hello, name!'문자열을 반환합니다. 1

UPDATE 나는 울부 짖는 코드를 시도 :

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; NSDictionary *parameters = @{@"name": @"tester"}; [manager POST:@"http://localhost/wp/?wsdl" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"JSON: %@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }];

얻을 eror :

Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x8ae1f00 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

나에게 몇 가지 조언을 바랍니다.

감사합니다.

답변

0

해결했습니다.

문제점 :

nuSOAP 서버를 사용한다. JSON을 반환하는 다른 웹 서비스로 바뀌고 이제는 클라이언트가 웹 서비스를 완벽하게 소비 할 수 있습니다.

관련 문제