【发布时间】:2013-12-20 09:41:48
【问题描述】:
我正在尝试将变量传递给 php 页面,但它没有传递给页面或保存在数据库中。请参阅以下代码中的 cmets:
NSString *fname=@"fname";
NSString *lname=@"lname";
NSString *urlString = [[NSString alloc] initWithFormat:@"http://localhost:8888/Test-objective%20c%20/send.php?first_name=%@&last_name=%@",fname,lname];
NSLog(urlString);
NSURL *url = [ NSURL URLWithString:urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSAlert *dq= [[NSAlert alloc] init];
[dq setMessageText:urlString];
[dq runModal];
[request setHTTPMethod:@"GET"];
NSURLConnection* connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection start];
NSAlert *d= [[NSAlert alloc] init];
[d setMessageText:@"connection"];
[d runModal];
//This is the part I don't understand.
//This line has a problem:
NSString *urlString = [[NSString alloc] initWithFormat:@"http://localhost:8888/Test-objectivec/send.php?first_name=%@&last_name=%@",fname,lname];
//But when I replace it with
NSString *urlString = @"http://localhost:8888/Test-objectivec/send.php?first_name=My&last_name=nme";
//Then it works just fine.
另外,谁能告诉我如何查看服务器的响应?
【问题讨论】:
-
将日志更改为
NSLog(@"URL string: %@", urlString);。调试,一切都创建了吗?
标签: php string cocoa nsurlconnection