使用 URL 从服务器脚本读取数据

发布于 2024-09-18 08:34:34 字数 1286 浏览 2 评论 0原文

我正在使用来自 iphone 的 http 调用在服务器上调用登录脚本。 该脚本根据给定的用户名/密码返回字符串“Invalid”或“valid”。

这是我正在使用的:

NSString *myurlstr = [[NSString alloc] initWithFormat:@"http://www.mysite.com/iph/login.aspx?用户名=%@&密码=%@",uname,pswd]; NSString *resultstr = [NSString stringWithContentsOfURL:[NSURL URLWithString:myurlstr] 编码:NSUTF8StringEncoding 错误:&错误];

NSLog(@"这是一个:%@",resultstr);

以下是控制台日志打印的内容:

测试尝试[51514:207] 这是一个:无效的登录名/密码

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

html xmlns="http://www.w3.org/1999/xhtml">

标题>标题> 无标题页面

/标题>/头>

正文

表单名称=“form1”方法=“post”action=“login.aspx?用户名=abc&密码=abc”id=“form1”>

输入类型=“隐藏”名称=“__VIEWSTATE”id=“__VIEWSTATE”值=“/wEPDwUJNzgzNDMwNTMzZGTnVSKZt+HQfSlQeCketelC9X+47A==”/>

div>

/div> /表格> /身体> /html>

有人可以帮助如何仅获取字符串(无效的登录名/密码)而不是从 DOCTYPE 开始的内容吗?

I am calling a login script on the server using http call from iphone.
the script returns a string "Invalid" or "valid" based on given username/pswd.

Here is what I am using:

NSString *myurlstr = [[NSString alloc] initWithFormat:@"http://www.mysite.com/iph/login.aspx?username=%@&password=%@",uname,pswd];
NSString *resultstr = [NSString stringWithContentsOfURL:[NSURL URLWithString:myurlstr] encoding:NSUTF8StringEncoding error:&error];

NSLog(@"HERE IS THE ONE: %@",resultstr);

Here is what the Console log prints:

TestingTrying[51514:207] HERE IS THE ONE: Invalid Login/Password

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

html xmlns="http://www.w3.org/1999/xhtml" >

head>title>
Untitled Page

/title>/head>

body>

form name="form1" method="post" action="login.aspx?username=abc&password=abc" id="form1">

input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJNzgzNDMwNTMzZGTnVSKZt+HQfSlQeCketelC9X+47A==" />

div>

/div>
/form>
/body>
/html>

Can someone help on how to get the string only(Invalid Login/Password) and not the content that starts from DOCTYPE onwards?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深爱不及久伴 2024-09-25 08:34:34

如果您只是询问如何从服务器响应中获取第一行,请使用标记器。 应该为您指明正确的方向,只需使用新行 / n 从内存中作为分隔符。

If your simply asking how to get the first line from your server response, use a tokenizer. This should point you in the right direction, just use new line which is /n from memory as the delimiter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文