2011-09-01 5 views
1

지금 문제가 있습니다. 나는 transactionID와 사용자 암호를 나머지 서비스에 전달해야하며, XML 값으로 true/false 값을 반환한다고 가정한다. 그러나, 그것은 지속적으로 나를 돌려 보내고 있습니다. (null).iphone에 웹 서비스가 남아 있습니다.

NSString *urlString = [NSString stringWithFormat:@"https://10.124.128.93:8443/axis2/services/C3WebService/completeWithdrawal Transaction?transactionId=%@&password=%@", _transactionID.text, _userPassword.text]; 

    NSURL *url = [[NSURL alloc] initWithString:urlString]; 
    NSString *result = [[NSString alloc] initWithContentsOfURL:url]; 


    NSLog(@"%@",result); 

내 결과는 계속 null을 반환합니다. 여기서 어떻게 계속합니까?

+0

[이] (http://stackoverflow.com/questions/2005448/how-to :

NSURL *url = [NSURL URLWithString:@"http://www.mysite.com"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; [request setHTTPMethod:@"GET"]; [[NSURLConnection alloc] initWithRequest:request delegate:self]; 

그럼 당신은 오류, 데이터 및 기타 세부 사항을 얻을 수있는 대리자 메서드를 구현할 수 있습니다 -use-nsxmlparser-to-parse-parent-child-elements-that-same-name/2005630 # 2005630) 구문 분석에 대한 적절한 아이디어를 제공합니다. –

답변

3

를 자세히 얻을 수있는 결과에 대한 콜백도 콜백을 가지고있는 NSURLConnection 사용을 고려 오류 정보. UI 스레드에서 실행되지 않습니다 (요청 중에 UI가 응답하지 않음).

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { 
    [responseData appendData:data]; 
} 

- (void) connectionDidFinishLoading:(NSURLConnection *)connection { 
    [connection release]; 

    NSString* responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 
    NSLog(@"result: %@", responseString); 

    [responseString release]; 
} 

- (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { 
     NSLog(@"error - read error object for details"); 
} 
+0

감사합니다 bryanMac ... 정확히 무엇이 필요합니다 =) –

+0

문제 없습니다. 또한이 문제를 더 많이 처리하는 RestKit과 같은 다른 프레임 워크가 있습니다. 확인 해봐. – bryanmac

+0

안녕하세요 Bryanmac ... "오류 - 자세한 내용을 보려면 오류 개체를 읽습니다."메시지 .. 여전히 연결할 수 없습니다 ... 문제가 무엇인지 알 수 있습니까? 감사합니다. 감사합니다. –

1

대신 "initWithContentsOfURL : encoding : error :"를 사용하고 "오류"를 확인해보십시오. 또한, 찰스 또는 다른 HTTP 스니퍼를 사용하여 직선 브라우저 요청에 결과를 비교 (브라우저에서 결과를 확인 했습니까?)

4
.h: 
    NSMutableData *responseData; 

.m: 
    - (void)load { 
     NSURL *myURL = [NSURL URLWithString:@"https://10.124.128.93:8443/axis2/services/C3WebService/completeWithdrawal Transaction?transactionId=%@&password=%@", _transactionID.text, _userPassword.text]; 
     NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myURL 
               cachePolicy:NSURLRequestReloadIgnoringLocalCacheData 
              timeoutInterval:60]; 

    [[NSURLConnection alloc] initWithRequest:request delegate:self]; 
} 

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { 
    responseData = [[NSMutableData alloc] init]; 
} 

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { 
    [responseData appendData:data]; 
} 

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { 
    [responseData release]; 
    [connection release]; 
    [textView setString:@"Unable to fetch data"]; 
} 

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
    NSLog(@"Succeeded! Received %d bytes of data",[responseData 
         `enter code here`        length]); 
    NSString *txt = [[[NSString alloc] initWithData:responseData encoding: NSASCIIStringEncoding] autorelease]; 

} 
관련 문제