首先,我正在做一个 Windows 应用程序。不是 Web 应用程序。
现在我正在开发从系统向手机发送 SMS(短消息)的应用程序。
在这里,我使用 http URL 推送具有参数 To(数字)和 Msg(测试消息)的消息。
形成URL后,如
这里我提到 3 为 ip 地址,X 为密码和用户 ID,因为保密。
发送此 URL 后,我在浏览器窗口中收到了一些文本,如“消息发送成功”。
只是我想读取文本并存储在数据库中。
我的问题是:如何从网络浏览器读取文本。
请抱紧我!
最佳答案
使用 .NET,参见 WebClient Class - 提供向 URI 标识的资源发送数据和从其接收数据的常用方法。
在这里看到过几次,例如fastest c# code to download a web page
编辑:System.Net.WebClient
类没有连接到 web 应用程序,可以很容易地在控制台或 winforms 应用程序中使用。 MSDN 链接中的 C# 示例是一个独立的控制台应用程序(编译并运行它以进行检查):
using System;
using System.Net;
using System.IO;
public class Test
{
public static void Main (string[] args)
{
if (args == null || args.Length == 0)
{
throw new ApplicationException ("Specify the URI of the resource to retrieve.");
}
WebClient client = new WebClient ();
client.Headers.Add ("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
Stream data = client.OpenRead (args[0]);
StreamReader reader = new StreamReader (data);
string s = reader.ReadToEnd ();
Console.WriteLine (s);
data.Close ();
reader.Close ();
}
关于C#:如何在 Windows 应用程序中从 Web 浏览器读取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/373872/