webclient

Windows Phone 8 Http request with custom header

懵懂的女人 提交于 2020-01-24 10:09:05
问题 I want to send a HTTP PUT request to a WCF server from Windows Phone 8, and for identification I have to send a custom header. (assume "mycustomheader" = "abc") I was using WebClient so far, but the Webclient.Headers seems not to have an Add method, so it is not possible to send headers other then the ones in HttpRequestHeader enum. Is there any way to do this with WebClient ? I saw it is possible to set a custom header with HttpWebRequest class, but I just can't get it to do anything at all.

Windows Phone 8 Http request with custom header

孤者浪人 提交于 2020-01-24 10:06:27
问题 I want to send a HTTP PUT request to a WCF server from Windows Phone 8, and for identification I have to send a custom header. (assume "mycustomheader" = "abc") I was using WebClient so far, but the Webclient.Headers seems not to have an Add method, so it is not possible to send headers other then the ones in HttpRequestHeader enum. Is there any way to do this with WebClient ? I saw it is possible to set a custom header with HttpWebRequest class, but I just can't get it to do anything at all.

C# WebClient - View source question

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-19 13:13:30
问题 I'm using a C# WebClient to post login details to a page and read the all the results. The page I am trying to load includes flash (which, in the browser, translates into HTML). I'm guessing it's flash to avoid being picked up by search engines??? The flash I am interested in is just text (not an image/video) etc and when I "View Selection Source" in firefox I do actually see the text, within HTML, that I want to see. (Interestingly when I view the source for the whole page I do not see the

C# WebClient - View source question

孤街醉人 提交于 2020-01-19 13:12:09
问题 I'm using a C# WebClient to post login details to a page and read the all the results. The page I am trying to load includes flash (which, in the browser, translates into HTML). I'm guessing it's flash to avoid being picked up by search engines??? The flash I am interested in is just text (not an image/video) etc and when I "View Selection Source" in firefox I do actually see the text, within HTML, that I want to see. (Interestingly when I view the source for the whole page I do not see the

UserState using WebClient and TaskAsync download from Async CTP

女生的网名这么多〃 提交于 2020-01-17 04:29:06
问题 I'm currently working with the Async CTP and need to convert this code into code where I can use Task.WhenAll(). What I did until now was using the UserState object and put my identifier (AID) into it and then use it in the completed event. However the wc.DownloadFileTaskAsync methode doesn't have an overload with UserState. What can I do? for (int i = 0; i < SortedRecommendations.Count; i++) { string tempfilepath = filepath + SortedRecommendations[i].Aid + ".jpg"; if (File.Exists

Use Webclient to download several files

妖精的绣舞 提交于 2020-01-16 19:17:27
问题 I'm trying to download files from webserver via a NUnit-testcase like this: [TestCase("url_to_test_server/456.pdf")] [TestCase("url_to_test_server/457.pdf")] [TestCase("url_to_test_server/458.pdf")] public void Test(string url) { using (WebClient client = new WebClient()) { client.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0)"); client.DownloadFile(new Uri(url), @"C:\Temp\" + Path.GetFileName(url)); } } This code works, but when i'm trying to get the file size, it hangs.

How to get the HTML encoding right in C#?

非 Y 不嫁゛ 提交于 2020-01-15 10:49:05
问题 I'm trying to get the pronunciation for certain word from a web dictionary. For example, in the following code, I want to get the pronunciation of good from http://collinsdictionary.com ( HTTP Agility Pack is used here) static void test() { String url = "http://www.collinsdictionary.com/dictionary/english/good"; WebClient client = new WebClient(); client.Encoding = System.Text.Encoding.UTF8; String html = client.DownloadString(url); HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack

WebClient().DownloadString() returning old data [duplicate]

一个人想着一个人 提交于 2020-01-15 03:01:25
问题 This question already has answers here : C# WebClient disable cache (12 answers) Closed 4 years ago . I am using this code to get the return string from URL webClient.Encoding = Encoding.UTF8; response = webClient.DownloadString("http://somesite.com/code.php"); Console.Write(response); the code.php looks like this <?php $data = file_get_contents('code.txt'); echo $data; ?> The problem is when I change the contents of the code.txt file, the webClient.DownloadString() method returns the old

NetworkCredential error in ASP.NET

…衆ロ難τιáo~ 提交于 2020-01-14 08:35:09
问题 I am trying to access a webpage through ASP.NET using the NetworkCredential class. However I keep getting an exception with the following message System.Security.Cryptography.CryptographicException: The handle is invalid Below is my code on how I am trying to call the function. Any help is greatly appreciated. C#: System.Net.WebClient client = new System.Net.WebClient(); client.Credentials = new System.Net.NetworkCredential("Admin", "Nimda"); Stack Trace [CryptographicException: The handle is

WP8 TaskCompletionSource not getting Result

这一生的挚爱 提交于 2020-01-14 06:31:10
问题 I've an extension method for WebClient (WP8) public static Task<string> DownloadStringTask(this WebClient webClient, Uri uri) { var tcs = new TaskCompletionSource<string>(); webClient.DownloadStringCompleted += (s, e) => { if (e.Error != null) { tcs.TrySetException(e.Error); } else if (e.Cancelled) { tcs.TrySetCanceled(); } else { tcs.TrySetResult(e.Result); } }; webClient.DownloadStringAsync(uri); return tcs.Task; } and the call to this method public string GetResult() { var task = new