webclient

A connection attempt failed because the connected party did not properly respond after a period of time or connected host has failed to respond

烂漫一生 提交于 2020-01-13 11:23:07
问题 I'm developing a windows service, that downloads images from a specific URL. The service runs correctly on my computer but when I install it in the server it does not download the image and it gives the following error: System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed

How to set HttpHeader on individual request using HttpClient

天涯浪子 提交于 2020-01-13 10:22:13
问题 I have an HttpClient that is shared across multiple threads: public static class Connection { public static HttpClient Client { get; } static Connection() { Client = new HttpClient { BaseAddress = new Uri(Config.APIUri) }; Client.DefaultRequestHeaders.Add("Connection", "Keep-Alive"); Client.DefaultRequestHeaders.Add("Keep-Alive", "timeout=600"); Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); } } It has some default headers I put onto each

Using a WebClient and C#, how do I get returned data even when the response is (400) Bad Request?

走远了吗. 提交于 2020-01-12 07:06:32
问题 I am using the Google Translate API and am trying to capture the data returned when I get an error. (FYI: I know the API Key is wrong, I am just testing this). The issue is that the browser, as you can see by clicking the link, displays the error info, but C# throws a WebException and I can't seem to get the response data. Here is my code: string url = "https://www.googleapis.com/language/translate/v2?key=INSERT-YOUR-KEY&source=en&target=de&q=Hello%20world"; WebClient clnt = new WebClient();

Using a WebClient and C#, how do I get returned data even when the response is (400) Bad Request?

我们两清 提交于 2020-01-12 07:05:46
问题 I am using the Google Translate API and am trying to capture the data returned when I get an error. (FYI: I know the API Key is wrong, I am just testing this). The issue is that the browser, as you can see by clicking the link, displays the error info, but C# throws a WebException and I can't seem to get the response data. Here is my code: string url = "https://www.googleapis.com/language/translate/v2?key=INSERT-YOUR-KEY&source=en&target=de&q=Hello%20world"; WebClient clnt = new WebClient();

Conditional repeat or retry on Mono with webclient from Spring WebFlux

爱⌒轻易说出口 提交于 2020-01-12 05:45:12
问题 What i want to do is a conditional repeat on a Mono in Webflux with webclient.The Situation is the following: We have some business rest service service that returns a generated document. the generation of this document is triggered from another service that gets called before this one. But, back to business: the document generation service needs from 10-30 seconds. What we want to do is: check after 10 seconds if document (Mono) is generated. If so, all is fine. If not, repeat (or retry)

Webclient's DownloadStringCompleted event handler never called

时间秒杀一切 提交于 2020-01-11 10:59:37
问题 I'm trying to make an asynchronous HTTP GET request using Webclient, however, the registered callback never gets called. I've also tried with the sync one, and it worked fine. What am I doing wrong? WebClient asyncWebRequest; public AsyncWebRequest(Uri url) { asyncWebRequest = new WebClient(); url = new Uri("http://www.google.com/"); // string test = asyncWebRequest.DownloadString(url); // this works asyncWebRequest.DownloadStringCompleted += new DownloadStringCompletedEventHandler

Silverlight Background Thread using WebClient

徘徊边缘 提交于 2020-01-11 07:57:18
问题 I'm using a WebClient to get infos asynchronously from my web service : wc.DownloadStringCompleted += DownloadStringCompleted; wc.DownloadStringAsync(service); I works fine, but I think the DownloadStringCompleted method is working on the UI Thread, and since i'm doing a lot of parsing there, my page takes a few seconds to appear. However, since I have so fixed data and a progress bar, I would'nt mind have it appearing instantly. How could I perfom this ? Thanks ! 回答1: Use HttpWebRequest

How to call a web service with a configurable URL

混江龙づ霸主 提交于 2020-01-07 07:48:06
问题 I wrote a web-service. I wrote a website. I want the website BLL code to call the web-service. I have a config table with this service URL. I inject the web-service URL to the calling code. What web client or socket in C# should I use that can receive a dynamic web-service URL? I thought to use: WebClient webClient = new WebClient(); UTF8Encoding response = new UTF8Encoding(); string originalStr = response.GetString(webClient.DownloadData(BLLConfig.Current); But maybe there is more elegant

URI Formats not Supported: while downloading remote file from Web client in c#

拈花ヽ惹草 提交于 2020-01-07 03:22:11
问题 I'm trying to download a file from the server . While passing a link to the download File , it is throwing an error **URI Formats are not supported ** and pointing at "link "- string contains server file address string link = http:\\www.nse-india.com\DERIVATIVES\2012\AUG\fo22AUG2012bhav.csv.zip WebClient wc = new WebClient(); var ua = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"; wc.Headers.Add(HttpRequestHeader.UserAgent, ua); wc.Headers["Accept"] = "/"; and

How to locate element with tag alert inside outer div

落爺英雄遲暮 提交于 2020-01-07 03:15:40
问题 I trying to locate elemnts in this page and put it in Objects (DomElement) to making some tests of it, the problem is with elemnt reg-error-yid it is a inner-div inside div yid-field-suggestion, I tried to getElementById, byName, byXPath, and getFirstByXPath it's all not working , also I tried to change webClient with WebDriver and use driver.findElement(By.className("oneid-error-message")) it's also not working the elemnt of registered message <div id="reg-error-yid" class="oneid-error