gpt4 book ai didi

iphone - 如何执行来自 iOS 应用程序的 URL 请求?

转载 作者:行者123 更新时间:2023-12-03 20:21:59 25 4
gpt4 key购买 nike

我想向服务器发送以下请求。服务器已经知道如何处理它,但是我该如何发送它呢?

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

更新:要进行异步请求,请参阅此 example

关于iphone - 如何执行来自 iOS 应用程序的 URL 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10968794/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com