WebClient 使用】的更多相关文章

AJAX不可以实现跨域请求,经过特殊处理才行.一般后台可以通过WebClient实现跨域请求~ //get 请求        string url = string.Format("http://localhost:28450/api/values?str1=a&str2=b");        WebClient wc = new WebClient();        Encoding enc = Encoding.GetEncoding("UTF-8"…
C#通过WebClient/HttpWebRequest实现http的post/get方法 http://www.cnblogs.com/shadowtale/p/3372735.html…
public class CreateBytes { Encoding encoding = Encoding.UTF8; /**/ /// <summary> /// 拼接所有的二进制数组为一个数组 /// </summary> /// <param name="byteArrays">数组</param> /// <returns></returns> /// <remarks>加上结束边界<…
数据提交 post  ,get public string WebClientPost(string PostData, string PostUrl, string Type) { string postString = PostData; byte[] postData = Encoding.UTF8.GetBytes(postString);//编码,尤其是汉字,事先要看下抓取网页的编码方式 string url = PostUrl;//地址 WebClient webClient = n…
最近更新了一个下载小工具,主要提升了下面几点: 1. 在一些分公司的局域网中,连接不上外网 2. 服务器上的文件更新后,下载到的还是更新前的文件 3. 没有下载进度提示 4. 不能终止下载 下面和大家分享一些心得. 鉴于各种复杂的网络环境,笔者决定采用不同的编程接口进行下载尝试,以增加程序的可用性. 这里仅介绍使用 WebClient 的方法,后续的文章会介绍其他的方法.博文中主要介绍思路和关键代码,完整的 demo 附在文末. 使用代理访问网络 很多公司的员工都是通过公司设置的代理上网的.通过…
WebClient位于System.Net命名空间下,通过这个类可以方便的创建Http请求并获取返回内容. 一.用法1 - DownloadData string uri = "http://hovertree.top/"; WebClient wc = new WebClient(); Console.WriteLine("Sending an HTTP GET request to " + uri); byte[] bResponse = wc.Download…
public string GetData(string url) { string data; using (var client = new WebClient()) { using (var stream = client.OpenRead(url)) { using (var reader = new System.IO.StreamReader(stream)) data = reader.ReadToEnd(); } } return data; } public string Po…
public void HttpDownload(string url, string path, ResourceType type) { using (var client = new WebClient()) { client.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"); client.Headers.Ad…
[编程环境]Visual Studio 2010, NET4.0 [开发语言]C#, 理论上VB.NET等依赖.NET Framework框架的语言均受此影响 [问题描述] 使用HttpWebRequest抓取网页内容,但首次请求总是莫名奇妙的阻塞在Request.GetResponse();上,不过一旦这次请求成功,后续的操作就很快了(如果是针对同一对象). 相同的代码编译在NET3.5环境中却一切正常,而在NET4.0环境中执行就出这问题,难道是一个BUG? [解决方案] 在配置文件中(.c…
由于项目需要,最近研究了下WebClient的数据传输.关于WebClient介绍网上有很多详细介绍,大概就是利用WebClient可以实现对Internet资源的访问.无外乎客户端发送请求,服务端处理请求.回应请求.所以,我下面就简单描述下学习过程中遇到的一些问题: 1.关于Winform客户端请求 WebClient wc = new WebClient();//初始化 webclient string path = "http://192.168.1.115:8089/Handler1.a…
这是我在项目中调用别人写好的接口口是使用的1.简单的url传参 List<ArticleModel> result = new List<ArticleModel>(); string str = string.Empty; string url = "http://transfer.61read.com/Service/ResourceService/GetArticleResourceList/access_token/" + accessToken + &…
根据黄聪:C#模拟网站页面POST数据提交表单(转) using System; using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; namespace Client { public class POST_DATA {…
//读取程序图标,来作为托盘图标this.notifyIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(System.Windows.Forms.Application.ExecutablePath); 线程池 ThreadPool.QueueUserWorkItem(callBack => { XiaoAoHelper.logout(); }); 解决办法: 1. 直接在窗体的构造函数中加:System.Windows.Forms.Co…
public static Main(string [] ager) { WebClient client = new WebClient(); client.Headers.Clear(); client.Headers.Add("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); client.Encoding = Encoding.UTF8; string responseStr…
前几天举例分析了用asp+xmlhttp获取网页源代码的方法,但c#中一般是可以利用WebClient类和WebRequest类获取网页源代码.下面分别说明这两种方法的实现. WebClient类获取网页源代码 WebClient类 WebClient类位于System.Net命名空间下,WebClient类提供向URI标识的任何本地.Intranet或Internet资源发送数据以及从这些资源接收数据的公共方法. 源代码 ///引用命名空间using System.IO;using Syste…
最近升级了公司内部使用的一个下载小工具,主要提升了下面几点: 1. 在一些分公司的局域网中,连接不上外网 2. 服务器上的文件更新后,下载到的还是更新前的文件 3. 没有下载进度提示 4. 不能终止下载 下面和大家分享一些心得. 鉴于各种复杂的网络环境,笔者决定采用不同的编程接口进行下载尝试,以增加程序的可用性. 这里仅介绍使用WebClient的方法.博文中主要介绍思路和关键代码,完整的demo附在文末. 使用代理访问网络 很多公司的员工都是通过公司设置的代理上网的.通过代理上网主要是方便公司…
线程机制(避免卡屏),异步下载文件. 我做网站的监控,WebClient.DownloadFile这个方法是我经常用到的,必要的时候肯定是要从网上下载些什么(WebRequest 也可以下载网络文件,不妨搜下,不过WebClient.DownloadFile使用更简单). 今天简单的演示下WebClient.DownloadFileAsync的使用,刚刚写好的实例,有问题你拍我. 解释什么的都不需要了吧.这里面应用了线程机制,异步调用.wo先展示代码,在把一些关键点放置到后面,并给一些修改建议(…
C#登录网站实际上就是模拟浏览器提交表单,然后记录浏览器响应返回的会话Cookie值,再次发送请求时带着这个会话cookie值去请求就可以实现模拟登录的效果了. 如下类CookieAwareWebClient实现在发送请求时都带着cookie. public class CookieAwareWebClient : WebClient {/* 何问起 hwq2.com */ private CookieContainer cookie = new CookieContainer(); prote…
static void Main(string[] args) { WebClient client = new WebClient(); client.Encoding = Encoding.GetEncoding("gb2312"); if (true) { WebProxy proxy = new WebProxy(); proxy.UseDefaultCredentials = false; proxy.Address = new Uri("http://183.23…
测试中发现webclient 比浏览器加载页面慢的一个问题:原因WebClient 支持 gzip, deflate,但是未设置 解决方案: class WebClientEx : WebClient { int timeout = 60; public WebClientEx(int timeout = 60) { this.timeout = timeout * 1000; this.Encoding = Encoding.UTF8;    } protected override WebR…
--post  请求 public static string PostMsg(Guid orgid, int page, int rows)        {            System.Net.WebClient client = new System.Net.WebClient(); string postData = "{\"groupid\": \"c3c5e53cd423480aa907f123338e0850\",\"typ…
解决SSH证书问题: webClient.getOptions().setUseInsecureSSL(true);//解决ssh证书访问https的问题…
private WebClient getAWebClient() { WebClient webClient = new WebClient(BrowserVersion.FIREFOX_24); webClient.getOptions().setTimeout(20000); // webClient.getCookieManager().setCookiesEnabled(true); webClient.getOptions().setThrowExceptionOnFailingSt…
System.Net.WebException was caught HResult=-2146233079 Message=An exception occurred during a WebClient request. Source=System StackTrace: at System.Net.WebClient.OpenRead(Uri address) at System.Net.WebClient.OpenRead(String address) at Client.Progra…
//webclient应用 MyImageServerEntities db = new MyImageServerEntities(); public ActionResult Index() { return View(); } public ActionResult FileUpload() { HttpPostedFileBase file = Request.Files["fileUp"]; string fileName = Path.GetFileName(file.Fi…
WebRequst的使用 WebClient和HttpWebRequst是用来获取数据的2种方式,在我的这篇数据访问(2)中主要是讲的WebClient的使用,一般而言,WebClient更倾向于“按需下载”,事实上掌握它也是相对容易的,而HttpWebRequst则允许你设置请求头或者对内容需要更多的控制,后者有点类似于form中的submit.虽然两者都是异步请求事件,但是WebClient是基于事件的异步,而HttpWebRequst是基于代理的异步编程,下面就用简单的需求两者比较用法上的…
//WebClient上传音频文件 public string UploadVoice(string fileNamePath) { Voice model=new Voice(); string saveUrl="D:/test"; string fileName=fileNamePath.Substring(fileNamePath.LastIndexOf("\\")+1); if(saveUrl.EndsWith("/")==false)…
namespace ConsoleAppSyncDownload{    class Program    { static void Main(string[] args)        {            WebClient webClient = new WebClient();            //Console.Write("输入下载文件地址:");            //var s = Console.ReadLine();            Conso…
System.Net.WebClient.DownloadFile(Uri address, String fileName) namespace:System.Net 参数: address:The URI from which to download data.fileName:The name of the local file that is to receive the data. eg: /// <summary> /// 保存文件到本地 /// </summary>…
下载数据 WebClient wc = new WebClient();1 string str= wc.DownloadString("地址")://直接下载字符串 2 wc.DownloadFile("addredd", "fileName");//下载文件 并指定下载到的地址 3  byte[] b=wc.DownloadData("address")//直接返回一个二进制数组 然后进行转换 wc.Dispose();…