Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-10-2009, 12:34 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 83
Default POSTing problem with NSURLConnection

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!
charpi is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 24,350
Threads: 39,142
Posts: 171,612
Top Poster: smasher (2,577)
Welcome to our newest member, 17make
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:27 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0