Hi all, I have a file in my "Sites" folder called "Boo.rtf", in it only contains the text "Boo". I want to change the text from "Boo" to "Hello World". Here is my code
Code:
- (IBAction)press {
NSLog(@"pressed");
NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://192.168.1.70/~Username/Boo.rtf"]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if(theConnection){
theData = [[NSMutableData alloc]initWithContentsOfURL:[NSURL URLWithString:@"http://192.168.1.70/~Username/Boo.rtf"]];
theString = [[NSMutableString alloc]initWithContentsOfURL:[NSURL URLWithString:@"http://192.168.1.70/~Username/Boo.rtf"]];
NSLog(@"theData: %@",theData);
NSLog(@"theString: %@",theString);
NSString *post = [NSString stringWithFormat:@"Hello World"];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding];
NSString *postLength = [NSString stringWithFormat:@"%d", [post length]];
NSMutableURLRequest *myRequest = [[[NSMutableURLRequest alloc]init]autorelease];
[myRequest setURL:[NSURL URLWithString:@"http://192.168.1.70/~Username/Boo.rtf"]];
[myRequest setHTTPMethod:@"POST"];
[myRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
[myRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[myRequest setHTTPBody:postData];
NSURLResponse *response = [[NSURLResponse alloc]init];
NSError *error = [[NSError alloc]init];
NSData *reply = [NSURLConnection sendSynchronousRequest:myRequest returningResponse:&response error:&error];
NSLog(@"reply: %@",reply);
NSLog(@"replyString: %@",[NSString stringWithCString:[reply bytes] length:[reply length]]);
}
}
all the permissions and settings for the files had been set to "Read and Write" for "Everyone". Is it necessary to do a chmod? Because right now I am able to access the file and see "Boo" from the replyString, but I'm not able to write "Hello World" onto the file.
Any suggestions?
Thanks alot!