2012-04-05 3 views
1

NSURL 대리자 didReceiveData 메서드가 호출되지 않지만 didReceiveResponse 및 didFinishLoading이 호출 중입니다. 나는 많은 온라인 게시물을 훑어 보았지만 어떤 데이터를받지 못하는지에 대한 단서를 얻을 수 없었다. 누군가가 코드에서 내가 무엇을하고 있는지 말할 수 있습니까? 어떤 도움을 주셔서 감사합니다. 여기 내 코드 :didReceiveData가 Xcode에서 호출되지 않음

- (IBAction)buttonClicked:(id)sender { 
NSString *soapMsg = 
[NSString stringWithFormat: 
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" 
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xlmns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" 
"<soap:Body>\n" 
"<GetAllCarsJson xmlns=\"http://cscserver2.carrollu.edu/tshah2/\">\n" 
"</GetAllCarsJson>\n" 
"</soap:Body>\n" 
"</soap:Envelope>"]; 

//---print it to the Debugger Console for verification--- 
//NSLog(@"%@",soapMsg); 
NSURL *url = [NSURL URLWithString:@"http://cscserver2.carrollu.edu/tshah2/CarService.asmx"]; 
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url]; 

//---set the headers--- 
NSString *msgLength = [NSString stringWithFormat:@"%d",[soapMsg length]]; 
[req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
[req addValue:@"http://cscserver2.carrollu.edu/tshah2/GetAllCarsJson" forHTTPHeaderField:@"SOAPAction"]; 
[req addValue:msgLength forHTTPHeaderField:@"Content-Length"]; 

//---set the HTTP method and body--- 
[req setHTTPMethod:@"POST"]; 
[req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]]; 

//[activityIndicator startAnimating]; 
conn = [[NSURLConnection alloc] initWithRequest:req delegate:self]; 
[conn start]; 

NSLog(@"Connection = %@", conn); 
if (conn) 
{ 
    //webData = [[NSMutableData data] ]; 
    webData = [[NSMutableData alloc] initWithCapacity:2048]; 
    //[[NSMutableData data] retainArguments]; 
} 
} 

- (void) connection:(NSURLConnection *) connection didReceiveResponse:(NSURLResponse *)response 
{ 
    NSLog(@"soapMsg1: %d", [webData length]); 
    //webData = [[NSMutableData alloc] initWith: 
    [webData setLength:0]; 
} 

- (void) connection:(NSURLConnection *) connection didReceiveData:(NSData *)data 
{ 
    NSLog(@"DONE1111"); 
    [webData appendData:data]; 
    //NSLog(webData); 

} 

- (void) connection:(NSURLConnection *) connection didFailWithError:(NSError *)error 
{ 
    NSLog(@"ConnectionFailed"); 
    //[webData release]; 
    //[connection release]; 
} 

- (void) connectionDidFinishLoading:(NSURLConnection *) connection 
{ 
    NSLog(@"DONE. Received Bytes: %d", [webData length]); 
    NSString *theXML = [[NSString alloc] initWithBytes:[webData mutableBytes] length:    [webData length] encoding:NSUTF8StringEncoding]; 

    //shows the XML 
    NSLog(theXML); 
    //[theXML release]; 
    //[activityIndicator stopAnimating]; 
    //[connection release]; 
    connection = nil; 
    webData =nil; 

} 

- (void) dealloc 
{ 
    //[activityIndicator release]; 
    //[xmlParser release]; 
    //[soapResults release]; 
    //[super dealloc]; 
} 
+0

strage : 빈 몸통을 다시 얻을 수 있습니까? 그래서 단지 헤더. 가능한? –

+0

NSLog for didReceiveResonse는 soapMsg1 : 0입니다. 또한 답장을 통해 명확히 할 수 있습니까? – vvg

답변

0

http 응답 코드를 확인하십시오. NSHTTPURLResponse 클래스의 - (NSInteger) statusCode 메소드 사용. 200이나 다른가요?

+0

NSHTTPURLResponse * httpResponse = (NSHTTPURLResponse *) 응답; int responseStausCode = [httpResponse statusCode]; NSLog (@ "code : % d", [httpResponse statusCode]; 상태 코드가 400으로 표시됩니다. – vvg

+0

HTTP 응답이 성공하면 응답 코드는 2xx이고 400은 서버가 요청한 형식이 올바르지 않다고 판단 할 수 있습니다. –

관련 문제