2

次のリクエストをサーバーに送信したいと思います。サーバーはそれをどう処理するかをすでに知っていますが、どうすれば送信できますか?

http://www.********.com/ajax.php?script=logoutUser&username=****
4

2 に答える 2

9

同期リクエストの場合、次のようにします。

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);
}

更新:非同期リクエストを実行するには、この例を参照してください

于 2012-06-10T12:43:32.417 に答える
0

できるよ:

NSString *resp = [NSString stringWithContentsOfURL:url usedEncoding:enc error: &error];
于 2013-05-13T21:07:23.787 に答える