webclient

Bad Request 400 - protocol error on a valid url - Webclient

痞子三分冷 提交于 2019-12-17 20:28:27
问题 I am trying to parse this page (http://www.coleparmer.co.uk/Product/Turb_Std_Hach_2100q_Kit/WZ-99900-47) using webclient and am having no luck. var client = new WebClient(); var html = client.DownloadString("http://www.coleparmer.co.uk/Product/Turb_Std_Hach_2100q_Kit/WZ-99900-47"); 回答1: The appropriate headers needs to be set. try { string html; using (WebClient client = new WebClient()) { client.Headers.Add("Accept-Language", " en-US"); client.Headers.Add("Accept", " text/html, application

PowerShell Script to upload an entire folder to FTP

南楼画角 提交于 2019-12-17 19:53:05
问题 I'm working on a PowerShell script to upload the contents of an entire folder to an FTP location. I'm pretty new to PowerShell with only an hour or two of experience. I can get one file to upload fine but can't find a good solution to do it for all files in the folder. I'm assuming a foreach loop, but maybe there's a better option? $source = "c:\test" $destination = "ftp://localhost:21/New Directory/" $username = "test" $password = "test" # $cred = Get-Credential $wc = New-Object System.Net

C# async methods still hang UI

本秂侑毒 提交于 2019-12-17 19:21:35
问题 I have these two methods, that I want to run async to keep the UI responsive. However, it's still hanging the UI. Any suggestions? async void DoScrape() { var feed = new Feed(); var results = await feed.GetList(); foreach (var itemObject in results) { var item = new ListViewItem(itemObject.Title); item.SubItems.Add(itemObject.Link); item.SubItems.Add(itemObject.Description); LstResults.Items.Add(item); } } public class Feed { async public Task<List<ItemObject>> GetList() { var client = new

WebClient class doesn't exist in Windows 8

这一生的挚爱 提交于 2019-12-17 18:37:44
问题 I want to use a HTTP webservice, and I've already developed an app for wp7. I use the WebClient class, but I can not use it for windows 8 ("error: type or namespace can not be found"). What else can I use? Can you provide me a sample of code? Does Microsoft have a site to help when a namespace don't exist? 回答1: Option 1 : HttpClient if you don't need deterministic progress notification this is what you want use. Example. public async Task<string> MakeWebRequest() { HttpClient http = new

POST'ing arrays in WebClient (C#/.net)

橙三吉。 提交于 2019-12-17 16:47:07
问题 I've got a .net application that has a WebRequest that to a POST adds multiple times the same key, thus making it an array in the eyes of PHP, Java Servlets etc. I wanted to rewrite this to using WebClient, but if I call WebClient's QueryString.Add() with the same key multiple times, it just appends the new values, making a comma-separated single value instead of an array of values. I post my request using WebClient's UploadFile() because in addition to these metadata I want a file posted.

HEAD with WebClient?

不羁岁月 提交于 2019-12-17 16:43:17
问题 I am going to assume the answer is no but.... Is there a way to use WebClient to send the HEAD method and return the headers as a string or something similar? 回答1: You are right WebClient does not support this. You can use HttpWebRequest and set the method to HEAD if you want this functionality: System.Net.WebRequest request = System.Net.WebRequest.Create(uri); request.Method = "HEAD"; request.GetResponse(); 回答2: Another way is to inherit from WebClient and override GetWebRequest(Uri address)

WebClient 403 Forbidden

孤街醉人 提交于 2019-12-17 16:34:25
问题 I can download this by hand in IE. http://scholar.google.com/scholar.ris?q=info:j8ymU9rzMsEJ:scholar.google.com/&output=citation&hl=zh-CN&as_sdt=2000&oe=GB&ct=citation&cd=0 But, using follow code WebClient client = new WebClient(); client.DownloadFile(address, filename); Show Exception: 403 Forbidden What's wrong? How can I do that? others http://scholar.google.com/scholar.ris?q=info:sskrpr5jlLwJ:scholar.google.com/&output=citation&hl=zh-CN&as_sdt=2000&oe=GB&ct=citation&cd=1 回答1: I get a 403

WebClient.DownloadFileAsync - Download files one at a time

青春壹個敷衍的年華 提交于 2019-12-17 15:59:08
问题 I am using the code below to download multiple attachments from a TFS server: foreach (Attachment a in wi.Attachments) { WebClient wc = new WebClient(); wc.Credentials = (ICredentials)netCred; wc.DownloadFileCompleted += new AsyncCompletedEventHandler(wc_DownloadFileCompleted); wc.DownloadFileAsync(a.Uri, "C:\\" + a.Name); } I would like to download multiple files using DownloadFileAsync, but I want them to be downloaded one by one. One may ask "Why don't you just use the synchronous

Winform文件下载之WinINet

随声附和 提交于 2019-12-17 14:15:08
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 在C#中,除了webclient我们还可以使用一组WindowsAPI来完成下载任务。这就是Windows Internet,简称 WinINet。本文通过一个demo来介绍WinINet的基本用法和一些实用技巧。 系列文章 Winform文件下载之WebClient 接口介绍 相比WebClient的用法,Win32API在使用时可能会烦琐一些。所以先把用到的API简单介绍一下。 资源的初始化和释放 InternetOpen 这是需要调用的第一个方法,它会初始化内部数据结构,为后面的调用做准备。 InternetCloseHandle 这个方法用来关闭使用中打开的Internet句柄,释放资源。 建立到服务器的连接 InternetOpenUrl 这是一个通用的函数,应用程序可以用它来请求数据(只要是WinINet支持的协议就可以)。尤其是当我们仅仅想要通过一个URL获取数据,而不关心通信协议相关的内容时,这个接口就特别合适。该方法会解析参数中的URL字符串,然后建立到服务器的连接,并准备下载由RUL标识的数据。 检查响应信息 HttpQueryInfo 检索与HTTP请求相关的报头信息。主要是查看请求是否成功。 读取响应内容 InternetReadFile 从

Accept Cookies in WebClient?

筅森魡賤 提交于 2019-12-17 09:30:44
问题 I just started experimenting with C# WebClient . What I have is the code below wich gets html code from a website and writes it in a .txt file. The only problem I have is that some websites require you to accept cookies before you can use the website. What this causes is instead of writing the real website html code to the .txt file, it writes the cookie popup html code. Code: string downloadedString; System.Net.WebClient client; client = new System.Net.WebClient(); //"http://nl.wikipedia.org