次のリクエストをサーバーに送信したいと思います。サーバーはそれをどう処理するかをすでに知っていますが、どうすれば送信できますか?
http://www.********.com/ajax.php?script=logoutUser&username=****
次のリクエストをサーバーに送信したいと思います。サーバーはそれをどう処理するかをすでに知っていますが、どうすれば送信できますか?
http://www.********.com/ajax.php?script=logoutUser&username=****
同期リクエストの場合、次のようにします。
NSURL *url = [NSURL URLWithString:@"http://www.********.com/ajax.php?script=logoutUser&username=****"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLResponse *response;
NSError *error;
//send it synchronous
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
// check for an error. If there is a network error, you should handle it here.
if(!error)
{
//log response
NSLog(@"Response from server = %@", responseString);
}
更新:非同期リクエストを実行するには、この例を参照してください
できるよ:
NSString *resp = [NSString stringWithContentsOfURL:url usedEncoding:enc error: &error];