webclient

DownloadString and Special Characters

孤者浪人 提交于 2019-12-24 01:52:14
问题 I am trying to find the index of Mauricio in a string that is downloaded from a website using webclient and download string. However, on the website it contains a foreign character, Maurício. So I found elsewhere some code string ToASCII(string s) { return String.Join("", s.Normalize(NormalizationForm.FormD) .Where(c => char.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark)); } that converts foreign characters. I have tested the code and it works. So the problem I have is that when I

MultiThreaded Proxy Checker

可紊 提交于 2019-12-24 01:07:57
问题 I have little code like: using (WebClient wc = new WebClient()) { wc.Proxy = new WebProxy("IP", Port); resume: if (!wc.IsBusy) { string rtn_msg = string.Empty; try { rtn_msg = wc.DownloadString(new Uri("http://google.com/")); } catch (WebException) { } catch (Exception) { } } else { System.Threading.Thread.Sleep(1000); goto resume; } } I am trying to use it with ThreadPool: foreach (Proxy proxy in s) { ThreadPool.QueueUserWorkItem((c) => { this.CheckProxy(proxy); }); } The problem is that the

Can't see WebClient post request in Fiddler

和自甴很熟 提交于 2019-12-24 00:56:33
问题 I have an ASP.NET WebForms app (sender) which sends a WebClient post request to another ASP.NET app (receiver) on the same dev machine. The WebClient post is initiated by clicking a button in the sender app. It's a test app and the form has only the button. I can see the post from the button in Fiddler but I don't see the post request from the WebClient method. Why? I know the WebClient post runs successfully because the breakpoint is hit in the receiver app and the Forms collection has the

Webclient using download file to grab file from server - handling exceptions

我只是一个虾纸丫 提交于 2019-12-24 00:55:44
问题 I have a web service in which I am manipulating POST and GET methods to facilitate upload / download functionality for some files in a client/server style architecture. Basically the user is able to click a button to download a specific file, make some changes in the app, then click upload button to send it back. Problem I am having is with the download. Say the user expects 3 files 1.txt, 2.txt and 3.txt. Except 2.txt does not exist on the server. So I have code like (on server side): public

WebClient website login

回眸只為那壹抹淺笑 提交于 2019-12-23 23:35:53
问题 I have difficulties logging in to a webpage (http://hurt.prosto.pl); all the time it returns to the login page source... Any idea how to fix it? var loginData = new NameValueCollection(); loginData.Add("username", username); loginData.Add("password", password); var client = new CookieAwareWebClient(); client.BaseAddress = @"http://hurt.prosto.pl/accounts/login/?next=/hurt/"; client.UploadValues("http://hurt.prosto.pl/accounts/login/?next=/hurt/", "POST", loginData); // now you are logged in

Can't send Content-Type header with c# HttpClient

橙三吉。 提交于 2019-12-23 19:11:52
问题 I'm trying to set a Content-Type header in a c# HttpClient request of "multipart/form-data; boundary=----WebKitFormBoundaryaYcxA3wAp5XMUV2w" . So far I've tried using TryAddWithoutValidation which does not throw any exception/error but when I watch the request in fiddler its just not added? See code below. client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "multipart/form-data; boundary=----WebKitFormBoundaryaYcxA3wAp5XMUV2w"); response = client.PostAsync("https://example

How safe is my custom SSL verification logic to handle excepted RemoteCertificateNameMismatch?

落花浮王杯 提交于 2019-12-23 18:34:15
问题 I try to upload a file to my domain https://vault.veodin.com/ which is hosted at webfaction.com When you open this url, the browser warns you about the name mismatch, because the SSL certificate is issued for webfaction.com and not for veodin.com Accordingly a sslPolicyError System.Net.Security.SslPolicyErrors.RemoteCertificateNameMismatch occurs when I try to upload a file to this domain using .Net WebClient. For my purpose it's enough to be sure that the upload target is hosted at *

Fail Fast with WebClient

我怕爱的太早我们不能终老 提交于 2019-12-23 12:03:09
问题 Using a modified WebClient, I download data periodically from a service with the following characteristics: The data download (~1GB) can take around 20 minutes Sometimes the service decides not to return any data at all (request hangs), or takes minutes to hours to return the first byte. I would like to fail fast in the event that the service does not return any data within a reasonable (configurable) amount of time, yet allow plenty of time for a download that is making progress to succeed.

Parallel request to scrape multiple pages of a website

孤人 提交于 2019-12-23 04:54:40
问题 I want to scrape a website with plenty of pages with interesting data but as the source is very large I want to multithread and limit the overload. I use a Parallel.ForEach to start each chunk of 10 tasks and I wait in the main for loop until the numbers of active threads started drop below a threshold. For that I use a counter of active threads I increment when starting a new thread with a WebClient and decrement when the DownloadStringCompleted event of the WebClient is triggered.

“Your API key is not valid on this domain” when calling Disqus from WP7

混江龙づ霸主 提交于 2019-12-23 04:24:16
问题 I'm trying to access the REST Disqus API using the following url: http://disqus.com/api/3.0/threads/listPosts.json ?api_key=myKey &forum=myForum &thread:ident=myIdent When I go to the url in Chrome, it works fine. When I try to download it in WebClient , I have difficulty: WebClient data = new WebClient(); Uri queryUri = new Uri(DisqusQuery + ident, UriKind.Absolute); data.DownloadStringCompleted += new DownloadStringCompletedEventHandler(onDownloadCompleted); data.DownloadStringAsync