webclient

HttpClient error with PostAsync method

随声附和 提交于 2019-12-10 18:33:49
问题 When making PostAsync call using HttpClient to a 3rd party API. I am seeing this error exactly when I do client.PostAsync. Any idea what could have been causing this? Code: public class JobController : AsyncController { public ActionResult ViewPage() { return View("~/Views/Pages/Submit.cshtml"); } private const string ServiceUrl = "https://api.3points.io/v1/applications/"; [HttpPost] public async Task<ActionResult> Submit() { var client = new HttpClient(); var formData = new

Unable to read data from the transport connection:An existing connection was forcibly closed by the remote host

放肆的年华 提交于 2019-12-10 18:19:25
问题 I have problem when I try download source page from morizon.pl: WebClient webClient = new WebClient(); try { string str = webClient.DownloadString("https://www.morizon.pl/"); } catch (Exception ex) { Console.WriteLine(ex); } I checked similar problem in stackoverflow and edit my code and still nothing, I'm stuck with this problem. public class CookieAwareWebClient : WebClient { public CookieContainer CookieContainer { get; set; } public CookieAwareWebClient() : this(new CookieContainer()) { }

.net webclient returns 500 error, but url in browser is fine

让人想犯罪 __ 提交于 2019-12-10 17:34:10
问题 When I connect to a url via a web client, it returns a 500 internal server error. I can visit that URL in my browser just fine. This was working for months and the problem started yesterday. No changes on my end. I understand that a 500 status code is a server error, but I wanted to see if there was something else I could do at this point as I'm freaking out. Example url: http://www.myfitnesspal.com/reports/printable_diary/chuckgross?from=2015-07-17&to=2015-07-17 The code: string results;

Encoding differences between using WebClient and WebRequest?

情到浓时终转凉″ 提交于 2019-12-10 16:50:00
问题 In getting some random spanish newspaper's index I don't get the diacriticals properly using WebRequest, they yield this weird character: � , while downloading the response from the same uri using a WebClient I get the appropriate response. Why is this differentiation? var client = new WebClient(); string html = client.DownloadString(endpoint); vs WebRequest request = WebRequest.Create(endpoint); using (WebResponse response = request.GetResponse()) { Stream stream = response.GetResponseStream

F#: only do one action once for the first event, without mutability/locking?

大憨熊 提交于 2019-12-10 15:45:00
问题 I have this code that downloads a file and tells me in the console how big is the file: use webClient = new WebClient() let lockObj = new Object() let mutable firstProgressEvent = true let onProgress (progressEventArgs: DownloadProgressChangedEventArgs) = lock lockObj (fun _-> if (firstProgressEvent) then let totalSizeInMB = progressEventArgs.TotalBytesToReceive / 1000000L Console.WriteLine ("Starting download of {0}MB...", totalSizeInMB) firstProgressEvent <- false ) webClient

Any way to access response body using WebClient when the server returns an error?

≡放荡痞女 提交于 2019-12-10 15:15:59
问题 Is there a way to access the response body when the response status is 4xx when using the WebClient class, for example: (webClient, evt) => // this is the event handler for the UploadStringCompleted event { if (evt.Error != null) { // can I access the response text? } }); 回答1: Since evt.Error is a WebException (rather than a vanilla Exception), here's what I do (please excuse the VB.NET): ''' <summary> ''' Extends a WebException to include any body text from the HTTP Response in the .Message

Why is my call to get Twitter user timeline returning “401 Unauthorized.”? [duplicate]

ε祈祈猫儿з 提交于 2019-12-10 14:46:56
问题 This question already has answers here : Authenticate and request a user's timeline with Twitter API 1.1 oAuth (2 answers) Closed last year . I have the following code shamelessly taken from dev.twitter to get the time line of a specific user: string endpoint = "https://api.twitter.com/1.1/statuses/user_timeline.json"; string user_name = "....."; string ConsumerKey = "...."; string ConsumerSecret = "........"; string Token = "......."; string TokenSecret = "........"; // oauth application

How to use WebClient without blocking UI?

不问归期 提交于 2019-12-10 13:59:39
问题 Can someone point me to a tutorial or provide some sample code to call the System.Net.WebClient().DownloadString(url) method without freezing the UI while waiting for the result? I assume this would need to be done with a thread? Is there a simple implementation I can use without too much overhead code? Thanks! Implemented DownloadStringAsync, but UI is still freezing. Any ideas? public void remoteFetch() { WebClient client = new WebClient(); // Specify that the DownloadStringCallback2 method

VB6 Download Web Page Source

时光怂恿深爱的人放手 提交于 2019-12-10 13:54:39
问题 Is there a way in VB6 to download a web pages source to a string or Textbox? For example in VB.Net the WebClient class allows you to do so using .DownloadString("google.com"), how can I do the same in vb6? Note: I would like to avoid using a WebBrowser. 回答1: I don't know much about VB6, but in VBA... Dim objHttp As Object, strURL as string, strText as string Set objHttp = CreateObject("MSXML2.ServerXMLHTTP") strURL = "http://www.yoursite.com/" objHttp.Open "GET", strURL, False objHttp

DownloadStringAsync blocks thread for 14 seconds on first call

萝らか妹 提交于 2019-12-10 13:49:06
问题 This only happens on one of my machines. I think it's an environment configuration problem. All machines run ESET Smart Security software firewall. Any ideas? using System; using System.Net; using System.Diagnostics; using System.Threading; namespace Test { static class Program { [STAThread] static void Main() { bool exit = false; WebClient wc = new WebClient(); DateTime before = DateTime.Now; wc.DownloadStringAsync(new Uri("http://74.125.95.147"), "First"); // IP Address of google, so DNS