webclient

How to set User-Agent in WebClient

∥☆過路亽.° 提交于 2019-12-18 09:28:25
问题 I used the code below to open a stream request to a youtube video, but it always return an exception "The remote server returned an error: NotFound". Then I tried to use Fiddler to detect the problem, and I saw that the WebClient auto set User-Agent field to NativeHost, not my User-Agent as below. My code to send a request to youtube: private static Task<string> HttpGet(string uri) { var task = new TaskCompletionSource<string>(); var web = new WebClient(); web.OpenReadCompleted += (sender,

Is there an upload limit when using Web Client in C#?

不打扰是莪最后的温柔 提交于 2019-12-18 08:58:09
问题 Using UploadFile("upload.php", "POST", filePath) with WebClient anything over 4mb will not upload. The limit in PHP is set at 48mb. Is there I need to set in C# ? 回答1: There is a default maxRequestLength set at 4MB in ASP.NET, you can change it in the web.config. <configuration> <system.web> <!-- This will handle requests up to 1024MB (1GB) --> <httpRuntime maxRequestLength="1048576" timeout="3600" /> </system.web> </configuration> The length is specified in KB in the config file. If you are

Get html that is generated via AJAX in webclient

风格不统一 提交于 2019-12-18 08:57:17
问题 I often go to a site to look stuff up. I thought to myself: "Hold on. I can program. Why am I going to this site manually when I can write a piece of software that does it for me?". And so I started. I'm using C#, so I found WebClient and Uri. I've managed to get the source code for the site, yet the problem occurred that the specific data I'm looking for is generated via AJAX, after the source code has loaded. So that's my problem. How can I get that code, if it needs to be requested via an

Remote server (403) Forbidden error while using WebClient

允我心安 提交于 2019-12-18 08:44:27
问题 I am trying to query some URL using WebClient . I have a collection which I loop through to get the QueryString value, and build final URL, and then pass it on to client. The very first time it gets executed well, I get proper response, however, when it goes in loop second time, I get the error: System.Net.WebException --> The remote server returned an error: (403) Forbidden. If I get response for very first time. Then I should get for rest of the collection too. Any clue why? What I might be

WebClient AsyncUpload progress percentage always returns 50%

你说的曾经没有我的故事 提交于 2019-12-18 06:54:08
问题 i am using Webclient to upload data using Async call to a server, WebClient webClient = new WebClient(); webClient.UploadDataAsync(uri , "PUT", buffer, userToken); i've attached DatauploadProgress and DatauploadCompleted Events to appropriate callback functions // Upload Date Progress webClient.UploadProgressChanged += new UploadProgressChangedEventHandler(UploadProgressCallback); // Upload Date Progress void UploadProgressCallback(object sender, UploadProgressChangedEventArgs e) { // Magic

WebClient is very slow

筅森魡賤 提交于 2019-12-18 04:45:14
问题 I have problem with Webclient. It is very slow. It takes about 3-5 seconds to downloadString from one website. I don't have any network problems. This is my Modifed WebClient. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; namespace StatusChecker { class WebClientEx: WebClient { public CookieContainer CookieContainer { get; private set; } public WebClientEx() { CookieContainer = new CookieContainer(); ServicePointManager

C# Webclient Stream download file from FTP to local storage

可紊 提交于 2019-12-18 04:16:12
问题 I've been downloading files from an FTP server via the WebClient object that the .NET namespace provides and then write the bytes to a actual file via a BinaryWriter . All is good. However, now, the files have dramatically increased in size and I'm worried about memory constraints so I'd like to create a download stream, create an file stream, and line by line read from the download and write to the file. I'm nervous since I couldn't find a nice example of this. Here's my end result: var

Download file from FTP with Progress - TotalBytesToReceive is always -1?

蹲街弑〆低调 提交于 2019-12-18 03:39:06
问题 I am trying to download a file from an FTP server with a progress bar. The file is downloading, and the ProgressChanged event is calling, except in the event args TotalBytesToReceive is always -1. TotalBytes increases, but I am unable to calculate the percentage without the total. I imagine I could find the file size through other ftp commands, but I wonder why this doesn't work? My code: FTPClient request = new FTPClient(); request.Credentials = credentials; request.DownloadProgressChanged +

Best practices for using ServerCertificateValidationCallback

江枫思渺然 提交于 2019-12-17 23:15:37
问题 I am working on a project that uses some HTTP communication between two back-end servers. Servers are using X509 certificates for authentication. Needless to say, when server A (client) establishes connection to server B (server), there is a SSL/TLS validation error, since certificates used are not from trusted 3rd party authority. Normally, the way to handle it is using ServicePointManager.ServerCertificateValidationCallback , such as: ServicePointManager.ServerCertificateValidationCallback

Downloaded file using webclient.DownloadFileAsync has 0KB

人盡茶涼 提交于 2019-12-17 20:32:28
问题 I'm trying to download zend-framework (from http://framework.zend.com/releases/ZendFramework-1.11.11/ZendFramework-1.11.11.zip) simply using WebClient string url = "http://framework.zend.com/releases/ZendFramework-1.11.11/ZendFramework-1.11.11.zip"; WebClient downloader= new WebClient(); downloader.DownloadFileAsync(new Uri(url), "C:\\temp.zip"); The file is created, but it is empty. I checked response using fiddler and I get HTTP 200, correct content-length but "connection: closed" and