Objective-C ,ios,iphone开发基础:http网络编程

 

- (IBAction)loadData:(id)sender {
    
   
    NSURL* url = [NSURL URLWithString:@"http://162.105.65.251:8080/service/downloadusernote?user_name=weishouqiang"];
    NSURLRequest* request = [[NSURLRequest alloc] initWithURL:url];
    NSURLConnection* conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    [conn release];
    [request release];
    [upTextView resignFirstResponder];
    [downTextView resignFirstResponder];

    
}

- (IBAction)upLoad:(id)sender {
    
    NSData* upData = [upTextView.text dataUsingEncoding:NSUTF8StringEncoding];
    NSURL* url = [NSURL URLWithString:@"http://162.105.65.251:8080/service/uploadusernote?user_name=weishouqiang"];
    NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:url];
    [request setHTTPMethod:@"POST"];
    [request setValue:[NSString stringWithFormat:@"%ld",[upData length]]forHTTPHeaderField:@"Content-Length"];
    [request setHTTPBody:upData];
    NSURLConnection* conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    [conn release];
    [request release];
    [upTextView resignFirstResponder];
    [downTextView resignFirstResponder];
}

 

你可能感兴趣的:(Objective-C)