enbr
enbr

Reputation: 1203

NSURL not working

I wanted to ask if anyone could help he get this code to work. Nothing is showing up in my MySQL database. Thanks, enbr.

NSString *urlstr = [[NSString alloc] initWithFormat:@"http://mysite.come/myapp/submitrating.php?name=%@&comment=%@&rating=%@",
                    [selectedItem objectForKey:@"name"], comment.text, selectedRating];
NSString *urlstrEncoded = [urlstr stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [[NSURL alloc] initWithString:urlstrEncoded];
[urlstr release];
[url release];

Upvotes: 0

Views: 1155

Answers (3)

enbr
enbr

Reputation: 1203

I got it to work with this code.

NSString *urlstr = [NSString stringWithFormat:@"http://mysite.com/myapp/submitrating.php?name=%@&comment=%@&rating=%@", [selectedItem objectForKey:@"name"], comment.text, selectedRating];
NSString *urlEncoded = [urlstr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [[NSURL alloc] initWithString:urlEncoded];
NSString *ans = [NSString stringWithContentsOfURL:url encoding:NSASCIIStringEncoding error:nil];

Upvotes: 0

ennuikiller
ennuikiller

Reputation: 46965

You need to do much more than that! At minimum you need the following:

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:theURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];



NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

along with implementing the following methods:

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response

Upvotes: 2

Ben Zotto
Ben Zotto

Reputation: 70998

You're not doing anything with the URL object except creating it. Perhaps you want to try an NSURLConnection?

Upvotes: 1

Related Questions