我想將一個變量傳遞給一個php頁面,但它沒有被傳遞到頁面或被保存在數據庫中。請參閱以下代碼中的註釋:從目標C發送變量到php Cocoa
NSString *[email protected]"fname";
NSString *[email protected]"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);'。調試,創建了一切嗎? – Wain