#region 读取指定URL的内容
/// <summary>
/// 读取指定URL的内容
/// </summary>
/// <param name="URL">指定URL</param>
/// <param name="Content">该URL包含的内容</param>
/// <returns>读取URL的状态</returns>
public static string ReadHttp(string URL, ref string Content)
{
return ReadHttp(URL, "GET", ref Content);
}
public static string ReadHttp(string URL, string method, ref string Content)
{
string status = "ERROR";
HttpWebRequest Webreq = (HttpWebRequest)WebRequest.Create(URL);
Webreq.Method = method;
HttpWebResponse Webresp = null;
StreamReader strm = null;
try
{
Webresp = (HttpWebResponse)Webreq.GetResponse();
status = Webresp.StatusCode.ToString();
Encoding encod;
if (Webresp.CharacterSet.ToLower() == "utf-8")
{
encod = Encoding.GetEncoding("utf-8");
}
else
{
encod = Encoding.GetEncoding("gb2312");
}
strm = new StreamReader(Webresp.GetResponseStream(), encod);
Content = strm.ReadToEnd();
}
catch (Exception ex)
{
}
finally
{
if (Webresp != null) Webresp.Close();
if (strm != null) strm.Close();
}
return (status);
}
#endregion

C# 读取指定URL的内容的更多相关文章

  1. python 读取指定div的内容

    # -*- coding:utf-8 -*- from bs4 import BeautifulSoup import urllib.request import re # 如果是网址,可以用这个办法 ...

  2. Python3 urllib抓取指定URL的内容

    最近在研究Python,熟悉了一些基本语法和模块的使用:现在打算研究一下Python爬虫.学习主要是通过别人的博客和自己下载的一下文档进行的,自己也写一下博客作为记录学习自己过程吧.Python代码写 ...

  3. python读取指定内存的内容

    import ctypes as ct t = ct.string_at(0x211000, 20) # (addr, size) print t 最好不要用解释性语言来开发底层,一般用C.

  4. Python configparser 读取指定节点内容失败

    # !/user/bin/python # -*- coding: utf-8 -*- import configparser # 生成一个config文件 config = configparser ...

  5. iOS案例:读取指定txt文件,并把文件中的内容输出出来

    用到的是NSString中的initWithContentsOfFile: encoding方法 // // main.m // 读取指定文件并输出内容 // // Created by Apple ...

  6. javascript怎么获取指定url网页中的内容

    javascript怎么获取指定url网页中的内容 一.总结 一句话总结:推荐jquery中ajax,简单方便. 1.js能跨域操作么? javascript出于安全机制不允许跨域操作的. 二.用ph ...

  7. 向指定URL发送GET方法获取资源,编码问题。 Rest风格

    http编码.今天遇到获取网页上的数据,用HTTP的GET请求访问url获取资源,网上有相应的方法.以前一直不知道什么事rest风格,现在我想就是开一个Controller,然后使人可以调用你的后台代 ...

  8. 微博一键分享主要通过对指定 URL 添加各种参数来实现;

    微博一键分享主要通过对指定 URL 添加各种参数来实现:也可以用在线生成器自动生成. 示例: 搜狐微博一键分享 URL,只需三个参数: http://t.sohu.com/third/post.jsp ...

  9. VBA读取word中的内容到Excel中

    原文:VBA读取word中的内容到Excel中 Public Sub Duqu()      Dim myFile As String     Dim docApp As Word.Applicati ...

随机推荐

  1. Ubuntu 下编译安装linux

    1. 准备工作切换为管理员权限,sudo –i 输入用户密码 进入root 权限apt-get install build-essential kernel-package libncurses5-d ...

  2. hdu 4000 Fruit Ninja 树状数组

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4000 Recently, dobby is addicted in the Fruit Ninja. ...

  3. window.showModalDialog的传值和返回值

    window.showModalDialog(URL,dialogArgments,features) 打开一个新窗口 URL为要将打开的网页地址. dialogArgments为设定好传递给新视窗网 ...

  4. html5离线存储

    为了提升Web应用的用户体验,我们在做网站或者webapp的时候,经常需要保存一些内容到本地.例如,用户登录token,或者一些不经常变动的数据. 随着HTML5的到来,出现了诸如AppCache.l ...

  5. HDU1013Digital Roots

    G - Digital Roots Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   ...

  6. Hadoop分布式配置

    本作品由Man_华创作,采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可.基于http://www.cnblogs.com/manhua/上的作品创作. 请先参照Linux安 ...

  7. BZOJ1502: [NOI2005]月下柠檬树

    Simpson法相当好用啊!神奇的骗分算法! /************************************************************** Problem: 1502 ...

  8. Chapter 6面向对象

    1.Python中预定义的函数在定义的时候有一种很特别的形式,即是函数名是小写,并且函数名前后分别有两个下划线.同样的,在对象中也有预定义的方法,例如所有对象的基类object中的__new__(), ...

  9. Using the viewport meta tag to control layout on mobile browsers

    A typical mobile-optimized site contains something like the following: <meta name="viewport& ...

  10. linux 安装python,pip,

    Linux下python升级步骤 http://www.cnblogs.com/lanxuezaipiao/archive/2012/10/21/2732864.html 在 https://www. ...