2009-07-30 1 views

답변

0

내가 그렇게 잃었어요

-(void)uploadSchedule:(id)sender 
{ 
    NSData *content = [NSData dataWithContentsOfFile:self.dataFilePath]; 
    NSString *stuff = [[NSString alloc] initWithData:content encoding:NSASCIIStringEncoding]; 

    NSURL *url = [NSURL URLWithString:@"http://thetis.lunarmania.com"]; 
    NSMutableURLRequest* urlRequest = [[NSMutableURLRequest alloc]initWithURL:url]; 
    [urlRequest setHTTPMethod:@"POST"]; 
    [urlRequest setHTTPBody:[stuff dataUsingEncoding:NSASCIIStringEncoding]]; 

    NSLog(@"great success!"); 
} 

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{ 
    // this method is called when the server has determined that it 
    // has enough information to create the NSURLResponse 

    // it can be called multiple times, for example in the case of a 
    // redirect, so each time we reset the data. 
    // receivedData is declared as a method instance elsewhere 

    [receivedData setLength:0]; 
} 

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{ 
    // append the new data to the receivedData 
    // receivedData is declared as a method instance elsewhere 

    [receivedData appendData:data]; 
} 

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 
{ 
    // release the connection, and the data object 
    [connection release]; 
    // receivedData is declared as a method instance elsewhere 
    [receivedData release]; 

    // inform the user 
    NSLog(@"Connection failed! Error - %@ %@", 
      [error localizedDescription], 
      [[error userInfo] objectForKey:NSErrorFailingURLStringKey]); 
} 

-(void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
    // do something with the data 
    UIImage *image = [[UIImage alloc] initWithData:receivedData]; 
    [cat setImage:image]; 
    [image release]; 

    // receivedData is declared as a method instance elsewhere 
    NSLog(@"Succeeded! Received %d bytes of data",[receivedData length]); 

    // release the connection, and the data object 
    [connection release]; 
    [receivedData release]; 
} 

-(void)connection:(NSURLConnection *)connection 
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge 
{ 
    if ([challenge previousFailureCount] == 0) { 
     NSURLCredential *newCredential; 
     newCredential=[NSURLCredential credentialWithUser:@"[email protected]" 
               password:@"icanican" 
               persistence:NSURLCredentialPersistenceNone]; 
     [[challenge sender] useCredential:newCredential 
       forAuthenticationChallenge:challenge]; 
    } else { 
     [[challenge sender] cancelAuthenticationChallenge:challenge]; 
     // inform the user that the user name and password 
     // in the preferences are incorrect 
     //[self showPreferencesCredentialsAreIncorrectPanel:self]; 
    } 
} 

... ...입니다 :

NSURLRequest - encode url for NSURLRequest POST Body (iPhone objective-C)

허용 된 대답은 ASIHTTPRequest를 사용 내가 사용했던 것과 비슷하며, HTML 폼에서 게시/가져 오기가 정말 쉽습니다. 여기

ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:@"http://someSite.com"] autorelease]; 
[request setPostValue:@"myValue1" forKey:@"myFormField1"]; 
[request setPostValue:@"myValue2" forKey:@"myFormField2"]; 
// etc. 
[request start]; 
NSError *error = [request error]; 
if (!error) 
    NSString *response = [request responseString]; 
1

코드는 충돌 (과거에 유래에서) 예입니다 당신 때문에 과다 방출 connection. Cocoa memory management rules을 검토하십시오.

그 외에도 문제가 무엇인지에 대해 구체적으로 설명해야합니다.

실제로 용어는 "인스턴스 변수"이며 "메서드 인스턴스"는 아닙니다. 인스턴스 변수는 인스턴스 내부의 변수이며 메소드와는 아무런 관련이 없습니다.

0

파일 크기가 큰 경우 을 사용하여 더하기 대신 didReceiveData에 데이터를 쓸 수 있습니다.