Tag: webclient

使用webclient类将文件上载到文件服务器

目前我有一个应用程序从我的Web应用程序接收上传的文件。 我现在需要将该文件传输到恰好位于同一网络上的文件服务器(但事实并非总是如此)。 我试图在C#.NET中使用webclient类。 string filePath = “C:\\test\\564.flv”; try { WebClient client = new WebClient(); NetworkCredential nc = new NetworkCredential(uName, password); Uri addy = new Uri(“\\\\192.168.1.28\\Files\\test.flv”); client.Credentials = nc; byte[] arrReturn = client.UploadFile(addy, filePath); Console.WriteLine(arrReturn.ToString()); } catch (Exception ex) { Console.WriteLine(ex.Message); } 位于192.168.1.28的计算机是文件服务器,共享c:\ Files。 截至目前,我收到登录失败的错误用户名或密码错误,但我可以打开资源管理器并输入该路径成功登录。 我也可以使用远程桌面登录,所以我知道用户帐户有效。 有关此错误的任何想法? 可以像这样直接传输文件吗? 使用webclient类或者其他类?

使用c#Webclient通过https请求html

我正在通过c#WebClient类从我无法控制的站点尝试各种html资源。 当我尝试访问“ https://archive.org/details/OTRR_In_The_Name_Of_The_Law_Singles ”等url时 我收到错误:System.Net.WebException:请求已中止:无法创建SSL / TLS安全通道。 我找到的解决方案建议我使用以下代码忽略证书要求并使webclient充当浏览器,但我仍然收到相同的错误 ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback( delegate { return true; }); using(WebClient webClient = new WebClient()) { webClient.Headers[“User-Agent”] = “Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729)”; webClient.Headers[“Accept”] = “text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8”; webClient.Headers[“Accept-Language”] = “en-us,en;q=0.5”; webClient.Headers[“Accept-Encoding”] = “gzip,deflate”; webClient.Headers[“Accept-Charset”] = “ISO-8859-1,utf-8;q=0.7,*;q=0.7”; StreamReader sr = new StreamReader(webClient.OpenRead(inputString)); […]

JsonConvert.DeserializeObject (string)为$ id属性返回null值

我正在使用System.Net.WebClient.DownloadString下载JSON。 我收到了有效回复: { “FormDefinition”: [ { “$id”:”4″, “Class”:558, “ClassDisplayLabel”:”Punchworks”, “Name”:”Punchworks Form” }, { “$id”:”6″, “Class”:558, “ClassDisplayLabel”:”Punchworks”, “Name”:”Punchworks Form test second” }, { “$id”:”46″, “Class”:558, “ClassDisplayLabel”:”Punchworks”, “Name”:”any_Name” }, { “$id”:”47″, “Class”:558, “ClassDisplayLabel”:”Punchworks”, “Name”:”Punchworks Form test second” }, { “$id”:”49″, “Class”:558, “ClassDisplayLabel”:”Punchworks”, “Name”:”Testing Name ??´????? ???? ACEeiÅ¡uu { [ ( ~ ! @ # ” }, { […]

如何检查System.Net.WebClient.DownloadData是否正在下载二进制文件?

我正在尝试使用WebClient使用WinForms应用程序从Web下载文件。 但是,我真的只想下载HTML文件。 我想要忽略的任何其他类型。 我检查了WebResponse.ContentType ,但它的值始终为null 。 任何人都知道原因是什么?

如何使用webclient异步下载多个文件,但一次只能一个?

很难找到使用webclient类异步方法下载多个文件的代码示例,但一次下载一个。 如何启动异步下载,但要等到第一个完成,直到第二个,等等。基本上是一个问题。 (注意我不想使用同步方法,因为异步方法的function增加了。) 以下代码立即启动我的所有下载。 (进度条到处都是) private void downloadFile(string url) { WebClient client = new WebClient(); client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged); client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted); // Starts the download btnGetDownload.Text = “Downloading…”; btnGetDownload.Enabled = false; progressBar1.Visible = true; lblFileName.Text = url; lblFileName.Visible = true; string FileName = url.Substring(url.LastIndexOf(“/”) + 1, (url.Length – url.LastIndexOf(“/”) – 1)); client.DownloadFileAsync(new Uri(url), […]

如何在C#中填写表单并使用Webclient提交

我很擅长在C#中使用库WebClient,HttpResponse和HttpRequest,所以请耐心等待,如果我的问题让人难以理解。 我需要构建一个基于C#的WinForm,它可以打开一个URL,该URL通过基本授权进行保护。 我这样做是将它添加到标题中,如下所示: using (WebClient wc = new WebClient()) { wc.Headers.Add(HttpRequestHeader.Authorization, “Basic ” + Convert.ToBase64String( Encoding.ASCII.GetBytes(username + “:” + password))); } 到现在为止还挺好! 现在我想填写一个带有数字的表单,然后我从网站上找到源代码,并发现名称是“数字”。 所以我写这个: NameValueCollection formData = new NameValueCollection(); formData[“number”] = number byte[] responseBytes = wc.UploadValues(theurl, “POST”, formData); string response = Encoding.ASCII.GetString(responseBytes); textBox_HTML.Text = response; 但是我该如何提交呢? 我想收到我的“搜索结果”……

如何validationWebClient请求?

我正在使用webclient调用我网站上的页面。 我试图将网页的结果放入pdf,所以我试图获得渲染页面的字符串表示。 问题是请求未经过身份validation,因此我得到的只是一个登录屏幕。 我已将UseDefaultCredentials属性发送到true,但我仍然得到相同的结果。 以下是我的代码的一部分: WebClient webClient = new WebClient(); webClient.Encoding = Encoding.UTF8; webClient.UseDefaultCredentials = true; return Encoding.UTF8.GetString(webClient.UploadValues(link, “POST”,form));

C# – 如何进行HTTP调用

我想对网站进行HTTP调用。 我只需要点击URL,不想上传或下载任何数据。 什么是最简单,最快速的方法。 我尝试了下面的代码,但它的速度很慢,并且在第二次重复请求之后,它只会进入59秒的超时并且恢复: WebRequest webRequest = WebRequest.Create(“http://ussbazesspre004:9002/DREADD?” + fileName); webRequest.Method = “POST”; webRequest.ContentType = “application/x-www-form-urlencoded”; webRequest.ContentLength = fileName.Length; Stream os = webRequest.GetRequestStream(); os.Write(buffer, 0, buffer.Length); os.Close(); 使用WebClient更有效率? WebClient web = new WebClient(); web.UploadString(address); 我正在使用.NET ver 3.5

WebClient访问具有凭据的页面

我正在尝试访问同一个域/同一个asp.net应用程序的网页,这是受密码保护的。 对于发起此呼叫的网页和正在访问的网页,凭据都是相同的。 这是代码,我不知道为什么我总是以登录表单html代码结束? using (WebClient client = new WebClient()) { client.QueryString.Add(“ID”, “1040”); //add parameters //client.Credentials = CredentialCache.DefaultCredentials; //I tried to add credentials like this client.Credentials = new NetworkCredential(“username”, “password”); string htmlCode = client.DownloadString(“http://domain.loc/testpage.aspx”); }

从Internet下载HTML后,字符串中的字符发生了变化

使用以下代码,我可以从互联网上下载文件的HTML: WebClient wc = new WebClient(); // …. string downloadedFile = wc.DownloadString(“http://www.myurl.com/”); 但是,有时文件包含“有趣”的字符,如é到é , ←到and和フシギダネ到フシギダム。 我认为它可能与不同的unicode类型或其他东西有关,因为每个角色变成2个新角色,也许每个角色被分成两半,但我对这个领域知之甚少。 你觉得怎么了?