Objective C in scrittura a URL remoto
-
30-09-2019 - |
Domanda
Ok, quindi ho il nome utente corretto / passare per un host remoto, e ho un oggetto NSURL
riferimento al file sul server.
Come posso scrivere dati su quel server tramite Objective-C? Non riesco a trovare nessuno con questo problema, in modo che l'aiuto sarebbe molto apprezzato!
Soluzione
Lo faccio tutto il tempo con il programma che sto scrivendo. La risposta dipende da quale server è stato installato e quali lingue supporta. Se, come credo, si dispone di PHP, basta inviare una richiesta GET al server e istruire il PHP per scrivere i dati che riceve.
Questa è una funzione di mine:
function checkInfo() {
$username = $_GET['username'];
$password = $_GET['password'];
connectToDataBase();
return returnSuccessObjectOn(isLoginInfoValid($username, $password));
}
Sul lato client:
NSURL *url = [NSURL URLWithString:kRequestLink];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:TIMEOUT];
OARequestParameter *reqCodeParameter = [[OARequestParameter alloc] initWithName:kParamReqCode value:[NSString stringWithFormat:@"%d",reqCode]];
[par addObject:reqCodeParameter];
[data enumerateKeysAndObjectsUsingBlock:composeRequestBlock];
[req setParameters:par];
NSLog(@"Sendind GET request: %@", [req description]);
activeConnection = [[NSURLConnection alloc] initWithRequest:req delegate:self startImmediately:YES];
Come si può vedere che uso blocchi
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow