Tag: webclient download

从Windows Phone 8中的URL获取JSON字符串

所以我试图在Windows Phone 8应用程序中从Url获​​取Json字符串。 我只需要调用一个返回此字符串的callbackurl,这就是它,但不知怎的,我已经被困在这几天了,我只是不明白该怎么做 我有一个urlparser类,包含2个方法: public void ParseJsonUrl(string url) { Uri uri = new Uri(url); WebClient webClient = new WebClient(); webClient.DownloadStringCompleted += webClient_DownloadStringCompleted; webClient.DownloadStringAsync(uri); } void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { var jsonData = JsonConvert.DeserializeObject(e.Result); Debug.WriteLine(jsonData.parameter1); } 现在我只是想显示我的Json字符串中包含的一个参数,当然我的方法会在我开始工作后执行其他操作 我在urlparser.cs文件的开头有一个名为“parameters”的类,看起来像 public class parameter { public string parameter1 { get; set; } public string parameter2 { get; […]

使用webclient从https下载文件时出错

我创建了一段代码,使用WebClient从给定的URL下载文件。 问题是当代码尝试从HTTPS站点下载文件时,我收到以下错误。 The remote certificate is invalid according to the validation procedure 此问题仅发生在不在本地计算机上的服务器上,因此我也不知道如何调试它。 我在网上看了几个答案,但没有找到任何可以帮助我的东西。 这段代码: using (WebClient Client = new WebClient()) { string fileName = System.Configuration.ConfigurationManager.AppSettings[“siteUploadedDirectory”] + “/temp/” + Context.Timestamp.Ticks.ToString() + “_” + FileURL.Substring(FileURL.LastIndexOf(‘/’)+1); fileName = Server.MapPath(fileName); Client.DownloadFile(FileURL, fileName); return fileName + “|” + FileURL.Substring(FileURL.LastIndexOf(‘/’)+1); } 我正在尝试的url: http://Otakim.co.il/printreferrer.aspx?ReferrerBaseURL=cloudents.com &ReferrerUserName=ram &ReferrerUserToken=1 &FileURL=https://www.cloudents.com/d/lzodJqaBYHu/pD0nrbAtHSq 文件URL:FileURL = https://www.cloudents.com/d/lzodJqaBYHu/pD0nrbAtHSq 任何帮助将不胜感激

C#进程无法访问文件,因为它正由另一个进程使用

请帮我解决我面临的问题。 我在C#中为xml文件编写了一个导入器。 每次运行导入时,我都需要从URL下载XML文件。 我已经下载了以下代码来下载它: var xmlPath = @”C:\Desktop\xxx.xml”; public void DownloadFile(string url, string saveAs) { using(var webClient = new WebClient()) { webClient.DownloadFileAsync(new Uri(url), saveAs); } } 和_downloader.DownloadFile(Config.FeedUrl, xmlPath); 调用方法。 Url位于配置文件( Config.FeedUrl )中。 然后,当我尝试GetProperties(xmlPath); 我得到exception“进程无法访问该文件,因为该文件正由另一个进程使用。 我确保目的地存在,但我不知道为什么我会收到此错误。 有人可以帮帮我吗? 谢谢

wb.DownloadFileAsync抛出“WebClient不支持并发I / O操作。”exception

我需要有关此代码的帮助 #region Events public class DownloadProgressChangedEventArg { private long _ProgressPercentage; private long _BytesReceived; private long _TotalBytesToReceive; public DownloadProgressChangedEventArg(long BytesReceived, long TotalBytesToReceive) { _BytesReceived = BytesReceived; _TotalBytesToReceive = TotalBytesToReceive; _ProgressPercentage = BytesReceived * 100 / (TotalBytesToReceive); } public long BytesReceived { get { return _BytesReceived; } set { _BytesReceived = value; } } public long ProgressPercentage […]

使用c#使下载可恢复

我正在使用此方法( WebClient类)从Internet下载文件: private Task DownloadUpdate(string url, string fileName) { var wc = new WebClient(); return wc.DownloadFileTaskAsync(new Uri(url), @”c:\download” + fileName); } 如何使用上面的代码使下载恢复 ?

远程服务器(403)使用WebClient时出现禁止错误

我试图使用WebClient查询一些URL。 我有一个集合,我循环访问以获取QueryString值,并构建最终的URL,然后将其传递给客户端。 它第一次执行得很好,我得到了适当的响应,但是,当它第二次进入循环时,我得到错误: System.Net.WebException – >远程服务器返回错误:(403)Forbidden。 如果我第一次得到回复。 然后我也应该收集其余的collections品。 有什么线索为什么? 我可能会缺少什么? 以下是我正在使用的代码段。 using(System.IO.StreamWriter file = new System.IO.StreamWriter(@”C:\sample.text”)) { foreach(var f in fileCollections) { strFinalURL = string.Empty; strFinalURL = “someURL” + f; // f can be considered as querystring param value try { using(var client = new WebClient()) { test = client.DownloadString(strFinalURL); if (!test.Contains(“somecondition”)) { file.WriteLine(“”); } […]

在我的下载程序中添加暂停和继续function

我正在用C#创建一个下载程序。 我正在使用WebClient类。 要在按钮上暂停下载,我可以考虑使用Thread。 因此,当我创建线程并将其与我的文件下载附加如下 WebClient web = new WebLCient(); Thread dwnd_thread = new Thread(Program.web.DownloadFileAsync(new Uri(Program.src), Program.dest)); 它给了我以下错误:“’System.Threading.Thread.Thread(System.Threading.ThreadStart)’的最佳重载方法匹配’有一些无效的参数”和“Argument’1’:无法从’void’转换为’ System.Threading.ThreadStart’”。 然后我想如果我暂停我的系统主线程然后它可以阻止我在下面的代码行使用的整个过程 System.Threading.Thread.Sleep(100); 但它什么都不做。 有人可以告诉我什么是更好的暂停/下载方法以及如何使用线程暂停我的下载过程。

将WebClient与socks代理一起使用

有没有办法在WebClient使用socks代理? 特别是它提供的DownloadString方法? 我不想使用任何第三方的东西,如privoxy,freecap,我不能使用像Chilkat那样的商业库。 我尝试使用来自http://www.mentalis.org/的东西,实际上我使用了他们的WebRequest实现,但它们似乎没有类似于WebClient的东西。