加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C#:如何在Windows应用程序中从webbrowser读取数据

发布时间:2020-12-15 22:56:22 所属栏目:百科 来源:网络整理
导读:首先,我正在做一个 Windows应用程序.不是Web应用程序. 现在我正在申请将SMS(短消息)从System发送到Mobile. 在这里,我使用http URL来推送具有参数To(number)和Msg(测试消息)的消息. 形成URL之后,就像 http://333.33.33.33:3333/csms/PushURL.cgi?USERNAME=xxx
首先,我正在做一个 Windows应用程序.不是Web应用程序.

现在我正在申请将SMS(短消息)从System发送到Mobile.

在这里,我使用http URL来推送具有参数To(number)和Msg(测试消息)的消息.

形成URL之后,就像

http://333.33.33.33:3333/csms/PushURL.cgi?USERNAME=xxxx&PASSWORD=xxxx&MOBILENO=919962391144&MESSAGE=TestMessage&TYPE=0&CONTENT_TYPE=text;

这里我提到3个用于ip地址,X用于密码和用户ID因为机密.

发送此URL后,我在浏览器窗口中收到一些文本,如“Message Send Successfully”.

我想阅读文本并存储在数据库中.

我的问题是:我如何从网络浏览器中读取文本.

请抱着我!

解决方法

使用.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 ();
}

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读