webclient

Using WebClient to access local files

早过忘川 提交于 2019-12-11 04:07:23
问题 I develop a C# application that needs to access many different content source both through HTTP, FTP and sometimes local files also (file://). I wanted to have a uniform way that I access these files through different protocols, so I had choosen WebClient to do this. It works well for all the different protocols as documented on MSDN (FTP, HTTP, local files, and so on), but then something goes wrong... after a couple successfull requests I just cannot access any files using URI for local

Can WebClient() download more than one string at the same time?

萝らか妹 提交于 2019-12-11 04:04:47
问题 I mean can I do something like this: var client = new WebClient(); var result = client.DownloadString(string("http://example.com/add.php"); var result2 = client.DownloadString(string("http://example.com/notadd.php")); in paralel like for 100 url's ? 回答1: In .NET 4.0, the simplest way is to use the ParallelExtensionsExtras's AsycCache along with the DownloadStringTask extension method. In fact, the example for this code covers your exact scenario: public sealed class HtmlAsyncCache :

WebClient DownloadFile displaying wrong percentage

。_饼干妹妹 提交于 2019-12-11 03:59:19
问题 I'm using a System.Net.WebClient to download a file asynchron in my application. For some reason, on some systems the percentage gets wrong calculated. My (updated) DownloadProgressChanged event: WebClient client = new WebClient(); client.DownloadProgressChanged += (_sender, _e) => { double bytesIn = _e.BytesReceived; double totalBytes = _e.TotalBytesToReceive; double percentage = bytesIn / totalBytes * 100; UpdateConnectingStatus("Missionsdatei wird heruntergeladen... (" + Math.Truncate

Using WebClient to ping a web site

橙三吉。 提交于 2019-12-11 03:56:33
问题 I have a tiny app that I wanting to run and ping an internal web site. Here is the code: using (var client = new WebClient()) { client.DownloadString("http://MyServer/dev/MyApp"); } However, it is throwing the following error: The remote server returned an error: (401) Unauthorized. I have all the correct credentials to access the server. I am thinking I don't know how to use WebClient very well and I just need to set properties on the client object. Any ideas? 回答1: I found the answer. I

Is this an inefficient way to parse XML?

佐手、 提交于 2019-12-11 03:27:56
问题 I'm probably worrying about wrong optimization, but I have this nagging thought that it's parsing the xml tree over and over and over again, maybe I read it somewhere. Can't remember. Anyways, here's what I'm doing: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Linq; using System.Net; namespace LinqTestingGrounds { class Program { static void Main(string[] args) { WebClient webClient = new WebClient(); webClient.DownloadStringCompleted

How to click a button in an webpage

回眸只為那壹抹淺笑 提交于 2019-12-11 02:47:53
问题 I'm using these code to download a file from the server. The link of the server from where I need to download the file is: http://www.mcxindia.com/sitepages/BhavCopyDateWise.aspx var forms = new NameValueCollection(); forms["__EVENTARGUMENT"] = ""; forms["__VIEWSTATE"] = ExtractVariable(s, "__VIEWSTATE"); forms["mTbdate"] = "12/22/2011"; forms["__EVENTVALIDATION"] = __EVENTVALIDATION; forms["mImgBtnGo"] = "?"; forms["__EVENTTARGET"] = "btnLink_Excel"; webClient.Headers.Set(HttpRequestHeader

.NET WebClient: Where is DownloadString?

倾然丶 夕夏残阳落幕 提交于 2019-12-11 01:57:23
问题 I'm probably missing something here, but when I use WebClient and look for the DownloadString method (as found in a book example), I only see DownloadStringAsync. What Import am I missing? 回答1: Are you using Silverlight? Only the Async version is available in Silverlight. Otherwise, the .NET 4 Framework and below (except 1.x) have the DownloadString() method. http://msdn.microsoft.com/en-us/library/ms144200.aspx 回答2: as indicated here, it looks like the DownloadString method is part of System

WebClient download string is different than WebBrowser View source

主宰稳场 提交于 2019-12-10 21:05:40
问题 I am create a C# 4.0 application to download the webpage content using Web client. WebClient function public static string GetDocText(string url) { string html = string.Empty; try { using (ConfigurableWebClient client = new ConfigurableWebClient()) { /* Set timeout for webclient */ client.Timeout = 600000; /* Build url */ Uri innUri = null; if (!url.StartsWith("http://")) url = "http://" + url; Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out innUri); try { client.Headers.Add("User-Agent",

Getting JSON string from URL in Windows Phone 8

情到浓时终转凉″ 提交于 2019-12-10 20:26:42
问题 So I'm trying to get a Json string from a Url in a windows phone 8 app. I just have to call a callbackurl that returns this string, and that's pretty much it, but somehow I've been stuck on this for days and I just don't understand how to do it I have a urlparser class that contains 2 methods which are : public void ParseJsonUrl(string url) { Uri uri = new Uri(url); WebClient webClient = new WebClient(); webClient.DownloadStringCompleted += webClient_DownloadStringCompleted; webClient

C# progress bar not synced with download (WebClient class)

守給你的承諾、 提交于 2019-12-10 19:38:56
问题 I am coding a system which has a small FTP module included inside, it's not the main feature at all, but needed... I must link the progressbar with the WebClient class event DownloadProgressChangedEventHandler and AsyncCompletedEventHandler, the progressbar increment is ok, and the ASyncCompletedEventHandler launch a MessageBox (as intended), the problem is that the progress bar see to load too slow... problem : My MessageBox pop at 100% (launched by the event handler), BUT when the