If you're sending a single URL request without needing to send multiple variations, NSURLRequest
will do. Even though you are using multiple parameters, they are all part of the same URL, so you just treat them that way. Build the URL as a string first and then use the string to initialize a NSURL
object.
You are prompting a log message on the server, but you will want to have response data in case something goes wrong. You can just ignore the response data unless there's an error. The request is sent using a NSURLConnection
object.
NSURL *urlToSend = [[NSURL alloc] initWithString: @"www.mypage.com/myscript.php?mynumber=99&myname=codezy"];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:urlToSend
cachePolicy:NSURLRequestReturnCacheDataElseLoad
cachetimeoutInterval:30];
NSData *urlData;
NSURLResponse *response;
NSError *error;
urlData = [NSURLConnection sendSynchronousRequest:urlRequest
returningResponse:&response
error:&error];
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…