 |
 |
|
 |
07-10-2009, 01:34 AM
|
#1 (permalink)
|
|
Registered Member
Join Date: Aug 2008
Posts: 74
|
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!
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 591 |
| 47 members and 544 guests |
| applezinga, blacksheep_2011, chinhminhdo, CHV, cordoprod, danny8, dany88, dcinqc, Dynno, ELA, Forsworn, Gandolf, guelinator, introiboad, issya, Janek2004, jbro, jhoncybpr, john3478, jschorn, Kalimba, kilobytedump, lifeCoder45, loobian, marciokoko, Mopedhead, Mr Jack, msudan, nathanp, noberasco, nycos, ovidiu, P2k, pereorra, RayKreisel, sascha, SmallWonder, supudo, svveet, totoro81, toughturtle, vcanic, walkman2001, wolfenberg, _Mac |
| Most users ever online was 779, 05-11-2009 at 10:55 AM. |
» Stats |
Members: 21,483
Threads: 35,768
Posts: 156,679
Top Poster: smasher (2,448)
|
| Welcome to our newest member, guelinator |
|