webrequest

Call asynchronous external web service in asp.net MVC controller

假如想象 提交于 2021-02-07 14:57:15
问题 In the Asp.net MVC controller (GET method) I am calling external web service - for geolocation of IP - returning json data for IP location. How can I make the call to be async, hence the stack can continue while waiting the response from the service. When the GEO IP request finished I want to be able to make update to the db. Here is the current sync code: public ActionResult SelectFacility(int franchiseId, Guid? coachLoggingTimeStampId) { //... string responseFromServer = Helpers

Powershell Invoke-RestMethod incorrect character

余生长醉 提交于 2021-02-07 12:53:20
问题 I'm using Invoke-RestMethod to get page names from an application I'm using. I notice that when I do a GET on the page it returns the page name like so This page â is working However the actual page name is This page – is working Here's how my request looks Invoke-WebRequest -Uri ("https://example.com/rest/api/content/123789") -Method Get -Headers $Credentials -ContentType "application/json; charset=utf-8" The problem is with the en-dash, does anyone know how I can fix this? 回答1: In case of

C# WebClient - DownloadString bad encoding

不问归期 提交于 2021-02-05 07:01:48
问题 I'm trying to download an html document from Amazon but for some reason I get a bad encoded string like "��K��g��g�e". Here's the code I tried: using (var webClient = new System.Net.WebClient()) { var url = "https://www.amazon.com/dp/B07H256MBK/"; webClient.Encoding = Encoding.UTF8; var result = webClient.DownloadString(url); } Same thing happens when using HttpClient: var url = "https://www.amazon.com/dp/B07H256MBK/"; var httpclient = new HttpClient(); var html = await httpclient

C# WebClient - DownloadString bad encoding

為{幸葍}努か 提交于 2021-02-05 07:01:04
问题 I'm trying to download an html document from Amazon but for some reason I get a bad encoded string like "��K��g��g�e". Here's the code I tried: using (var webClient = new System.Net.WebClient()) { var url = "https://www.amazon.com/dp/B07H256MBK/"; webClient.Encoding = Encoding.UTF8; var result = webClient.DownloadString(url); } Same thing happens when using HttpClient: var url = "https://www.amazon.com/dp/B07H256MBK/"; var httpclient = new HttpClient(); var html = await httpclient

Request uri too long with webservice

点点圈 提交于 2021-01-29 18:01:45
问题 I want to do a create via a webservice which needs a uri like this: http://<url>/webservice.php?operation=<operation>&elementType=<elementType>&element=<element>& my problem is, element is all information of an email with html body, which is about 6000 characters. I want to call the url like this: var request = WebRequest.Create(urlToUse.ToString()); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = urlToUse.Length; var requestStream =

Explicitly set TLSv1.2 in httpclient request in Angular

a 夏天 提交于 2021-01-29 12:07:27
问题 I am new to SSl/TLS protocols.I have back-end(API) wich is TLSv1.2 enabled. What I want to do is set the tls version for each and every request of my front-end(Angular) application.I want to prove that my application capable of sending TLSv1.2 request.Is there any way to set TLS version in angular web api request.Then i can change the TLS version and prove that. This is how consume web API. public methodName(): Observable<any[]> { return this.http .get<any>(`${config.apiUrl}url`) .pipe( map

Is it better to use HttpClient or WebRequest in ASP.NET Core to read the content of a file line by line asynchronously remotely?

吃可爱长大的小学妹 提交于 2021-01-29 08:12:04
问题 I plan to read a remote file line by line asynchronously using https://github.com/Dasync/AsyncEnumerable (since there is not yet Async Streams [C# 8 maybe]: https://github.com/dotnet/csharplang/blob/master/proposals/async-streams.md): public static class StringExtensions { public static AsyncEnumerable<string> ReadLinesAsyncViaHttpClient(this string uri) { return new AsyncEnumerable<string>(async yield => { using (var httpClient = new HttpClient()) { using (var responseStream = await

System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive

感情迁移 提交于 2021-01-27 19:04:03
问题 I'm trying to create a method in C# to return a string of a web pages html content from the url. I have tried several different ways, but I am getting the error System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. The following works fine locally, but gets the above error when running on a remote server: public static string WebPageRead(string url) { string result = String.Empty; WebResponse response = null; StreamReader reader = null; try

How to check status of list of Websites / URLs? (Using Power-Shell script)

帅比萌擦擦* 提交于 2020-03-05 06:05:19
问题 I want to take the http status of multiple URL at once to prepare a report. How to acheive it using powershell? 回答1: I have seen questions on monitoring multiple websites through windows machine. My friend wanted to check status of 200 URLs which he used to do manually. I wrote a Power-Shell script to overcome this. Posting it for the benefit of all users. Save the below code as "AnyName.ps1" file in "D:\MonitorWeb\" #Place URL list file in the below path $URLListFile = "D:\MonitorWeb\URLList

How do I use C# and ASP.net to proxy a WebRequest?

走远了吗. 提交于 2020-02-23 00:42:54
问题 pretty much...i want to do something like this: Stream Answer = WebResp.GetResponseStream(); Response.OutputStream = Answer; Is this possible? 回答1: No, but you can of course copy the data, either synchronously or asynchronously. Allocate a buffer (like 4kb in size or so) Do a read, which will either return the number of bytes read or 0 if the end of the stream has been reached If data was received, write the amount read and loop to the read Like so: using (Stream answer = webResp