Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.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, 01:34 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 90
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



» Advertisements
» Online Users: 900
22 members and 878 guests
2e1fmo, at0m87, aziz, Azuresilver, coding, Desert Diva, el.severo, fiftysixty, imran_ime4u, iVenh, jjaaxx44, nicko, Pasha2590, pratikchandak, Promo Dispenser, ramonpadillas, RoryHarvey, Thomas, ziocleto, Zuningo
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,312
Threads: 89,035
Posts: 379,822
Top Poster: BrianSlick (7,086)
Welcome to our newest member, 2e1fmo
Powered by vBadvanced CMPS v3.1.0

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