我想问一下是否有人可以帮助他让这段代码发挥作用。我的MySQL数据库中没有任何内容出现。谢谢,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];
答案 0 :(得分:2)
你需要做的远不止这些!至少您需要以下内容:
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:theURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
以及实施以下方法:
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
答案 1 :(得分:1)
除了创建URL对象之外,你不是使用做任何事情。也许您想尝试NSURLConnection
?
答案 2 :(得分:0)
我让它使用此代码。
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];