gpt4 book ai didi

objective-c - 在 iOS 中向服务器发送 GET 请求并从中获取生成的 html 页面数据

转载 作者:行者123 更新时间:2023-11-28 23:12:28 25 4
gpt4 key购买 nike

我在向服务器发送请求并从中获取生成的 html 页面数据时遇到了一些问题。例如,我知道像“http://www.xxxxxxxxxx.com”这样的网站,我应该向它发送一些像“http://www.xxxxxxxxx.com?groupid=1100”这样的参数。我怎样才能做到这一点?如何返回完整的 html 页面以及如何从返回的 html 页面返回数据?我的意思是例如

<body>
<p>Today</p>
<p>Today</p>
<p>Tomorrow</p>

我需要“今天今天明天”。请帮帮我!感谢您的帮助!!!!

创建 NSData

NSString *nameID = [[NSString alloc]initWithString: @"1"];        
NSString *urlString = [NSString stringWithFormat:@"http://www.xxxxx.com/news/index.php?id=%@",
[nameID stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

NSURL *url = [[NSURL alloc] initWithString:urlString];

NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];

NSData *urlData;
NSURLResponse *response;
urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:nil];
NSString *results = [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(@"%@",urlData);

我创建了 NSData,但如何解析它?

最佳答案

使用NSURLConnection用于通信(同步和异步可能:那里有很多教程)。我不会使用 html 作为对机器的响应。我会为此使用 xml 或 json,一些人可以更好地解析 xml-parserjson-parser

关于objective-c - 在 iOS 中向服务器发送 GET 请求并从中获取生成的 html 页面数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7847453/

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