httpwebrequest

How to enable response caching with HttpWebRequest on .NET Core

末鹿安然 提交于 2020-01-16 17:05:51
问题 This is a follow up to this question regarding caching responses to an HttpWebRequest . I have a WebApi server that returns a JSON response with an Expires header that indicates how long the response should be cached locally on the client. I have written a .Net Standard 2.0 library with code to enable a default RequestCachePolicy as follows: var policy = new RequestCachePolicy(RequestCacheLevel.Default); HttpWebRequest.DefaultCachePolicy = policy; var request = WebRequest.Create(url); ... etc

How to enable response caching with HttpWebRequest on .NET Core

偶尔善良 提交于 2020-01-16 17:04:10
问题 This is a follow up to this question regarding caching responses to an HttpWebRequest . I have a WebApi server that returns a JSON response with an Expires header that indicates how long the response should be cached locally on the client. I have written a .Net Standard 2.0 library with code to enable a default RequestCachePolicy as follows: var policy = new RequestCachePolicy(RequestCacheLevel.Default); HttpWebRequest.DefaultCachePolicy = policy; var request = WebRequest.Create(url); ... etc

How to catch ODataErrorException when I am making an OData call through HttpWebRequest in C#?

心已入冬 提交于 2020-01-16 15:57:07
问题 I am trying to call an OData service from my .Net console application using c#. I am using HttpWebRequest to make the call. Now if there is an OData specific error, for example, an invalid JSON payload, then an ODataErrorException is thrown from the OData server. My question is how to catch that ODataErrorException and extract the proper message out of it? The exception gets caught in WebException catch block, and it only shows me "400 Bad Request". But it doesn't show me the actual error

gdi+ error saving image from webpage

感情迁移 提交于 2020-01-16 14:19:20
问题 I have such method for saving image from url: public Image DownloadImage(string _URL) { Image _tmpImage = null; try { // Open a connection System.Net.HttpWebRequest _HttpWebRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(_URL); _HttpWebRequest.AllowWriteStreamBuffering = true; // You can also specify additional header values like the user agent or the referer: (Optional) _HttpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0

gdi+ error saving image from webpage

佐手、 提交于 2020-01-16 14:19:06
问题 I have such method for saving image from url: public Image DownloadImage(string _URL) { Image _tmpImage = null; try { // Open a connection System.Net.HttpWebRequest _HttpWebRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(_URL); _HttpWebRequest.AllowWriteStreamBuffering = true; // You can also specify additional header values like the user agent or the referer: (Optional) _HttpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0

how to send web request to check the link whether the link is broken or not [closed]

痞子三分冷 提交于 2020-01-16 10:43:30
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . i am having text box(multi line) from that i want to send the web request to all links to check whether the link is working or not if not working then message of error string strLink = TextBox1.Text; WebResponse

how to send web request to check the link whether the link is broken or not [closed]

一世执手 提交于 2020-01-16 10:43:11
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . i am having text box(multi line) from that i want to send the web request to all links to check whether the link is working or not if not working then message of error string strLink = TextBox1.Text; WebResponse

how to send web request to check the link whether the link is broken or not [closed]

一曲冷凌霜 提交于 2020-01-16 10:43:08
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . i am having text box(multi line) from that i want to send the web request to all links to check whether the link is working or not if not working then message of error string strLink = TextBox1.Text; WebResponse

Posting file on Background Agent / HttpWebRequest stream buffer keeps growing?

陌路散爱 提交于 2020-01-16 04:27:06
问题 I need to POST a 5MB file from within a ResourceIntensiveTask, where the OS sets a max memory usage of 5MB. So trying to stream the file directly from storage, but the Stream associated to the HttpWebRequest keeps growing in size. This is the code: public void writeStream(Stream writer, string filesource, string filename) { var store = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication(); var f = store.OpenFile(filesource, FileMode.Open, FileAccess.Read); store.Dispose()

How to reuse connection/request to avoid Handshake

家住魔仙堡 提交于 2020-01-15 12:21:44
问题 I would like to know how Reusing HttpWebRequests works to avoid SSL handshake process everytime. I use the keep alive headr in the request and the first handshake is successfull but i would like to reuse the request in order to avoid future handshakes against the same certificate. Think is i dont know if i had to reuse the HttpWebRequest object instance or even if i create a new request object it will use the same connection since the keep alive is already on place and working. Should i store