首页 > 开发 > 综合 > 正文

老外编的程序(八):在CSharp里面使用Http Get方法

2024-07-21 02:16:35
字体:
来源:转载
供稿:网友

/author: duncan mackenzie
using system;
using system.net;
using system.io;

namespace makeagetrequest_charp
{
    /// <summary>
    /// summary description for class1.
    /// </summary>
    class class1
    {
        static void main(string[] args)
        {
            string surl;
            surl = "http://www.microsoft.com";

            webrequest wrgeturl;
            wrgeturl = webrequest.create(surl);
            
            webproxy myproxy = new webproxy("myproxy",80);
            myproxy.bypassproxyonlocal = true;

            wrgeturl.proxy = webproxy.getdefaultproxy();

            stream objstream;
            objstream = wrgeturl.getresponse().getresponsestream();

            streamreader objreader = new streamreader(objstream);

            string sline = "";
            int i = 0;

            while (sline!=null)
            {
                i++;
                sline = objreader.readline();
                if (sline!=null)
                    console.writeline("{0}:{1}",i,sline);
            }
            console.readline();
        }
    }
}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表