dotnet-httpclient

Creating jira issue via Rest c# httpClient

a 夏天 提交于 2019-12-07 06:58:10
问题 I have read one answer on atlassian https://answers.atlassian.com/questions/79902/using-httpclient-c-to-create-a-jira-issue-via-rest-generates-bad-request-response where one user created a JIRA issue by the following code. I adapted it but get an error by using a self-build class issue with ObjectContent Http.HttpContent content = new Http.ObjectContent<Issue>(data, jsonFormatter); The compiler wont accept it. Does anybody know why? public string CreateJiraIssue() { string data= @"{ ""fields"

Difference between HttpClient and Unity's UnityWebRequest/WWW API

╄→尐↘猪︶ㄣ 提交于 2019-12-07 05:23:20
问题 Unity now supports .NET 4.5 and I'm able to use the HttpClient class from the System.Net.Http namespace. That is great since I have existing client libraries which are therefore easy to reuse. Does anyone know the internal difference between using the mono HttpClient and Unity's own networking classes? I'm afraid that the HttpClient is not as optimized for the different platforms and might therefore cause trouble or be slower. 回答1: There are many differences between the two. UnityWebRequest

Not able to connect to remote server from WinRT

和自甴很熟 提交于 2019-12-07 05:19:44
问题 I'm making an application which basically just needs to send a piece of XML to a server and return. I'm having trouble however getting this to work and getting very strange errors public bool Post(string data) { string server="http://my-lan-computer:9091/foo" bool success = false; HttpClient client = new HttpClient(); try { client.PostAsync(server, new StringContent(data, Encoding.UTF8, "text/xml")).Wait(); //error here success = true; } catch { } return success; } The server I'm posting to

How to prevent HttpClient from sending the Connection header

房东的猫 提交于 2019-12-07 02:28:42
问题 HttpClient includes this as 'Keep-Alive' by default. I've been able to set it to 'Close' using httpClient.DefaultRequestHeaders.ConnectionClose = true; but how do I omit it altogether? 回答1: I've seen this asked before and to my knowledge no one (not even the great Jon Skeet) has come up with a way to avoid sending the Connection header in the HttpClient or HttpWebRequest worlds without completely reinventing the wheel. It's happening somewhere very deep down in the weeds. ConnectionClose is

Progress bar for HttpClient uploading

℡╲_俬逩灬. 提交于 2019-12-07 01:33:17
问题 I want to run asynchronous uploads with a progress bar in WPF (and preferably use PCL for code reuse in Xamarin and SL too.) I've been trying to use System.Net.HttpClient. Unfortunately, PutAsync doesn't provide any progress notifications. (I know that it does for Windows.Web.Http.HttpClient, but that's not available for WPF, nor in the PCL). For downloading, its fairly easy to implement your own progress bar, as described here. You just pass the ResponseHeadersRead option, which makes the

Why does HttpClient appear to deadlock here?

放肆的年华 提交于 2019-12-07 00:33:27
I have an API made in a portable class library which needs to reach out to platform specific APIs for sending HTTP requests. Here is the method I wrote to do an HTTP POST on WinRT: public bool Post(IEnumerable<KeyValuePair<string, string>> headers, string data) { bool success = false; HttpClient client = new HttpClient(new HttpClientHandler {AllowAutoRedirect = false}); foreach (var header in headers) { client.DefaultRequestHeaders.Add(header.Key, header.Value); } try { var task=client.PostAsync(endpoint, new StringContent(data, Encoding.UTF8, "text/xml")).ContinueWith( postTask => { try {

Read headers from HttpResponseMessage before Content is 100% complete

僤鯓⒐⒋嵵緔 提交于 2019-12-06 20:16:13
问题 How do I access the response headers, before the entire response has been streamed back? How do I read the stream as it arrives? Is HttpClient my best choice for such granular control of receiving the http response? Here's a snip that might illustrate my question: using (var response = await _httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead)) { var streamTask = response.Content.ReadAsStreamAsync(); //how do I check if headers portion has completed? //Does

WP8 HttpClient.PostAsync never returns result

為{幸葍}努か 提交于 2019-12-06 14:34:00
问题 I have a Windows Phone 8 app where I am calling await HttpClient.PostAsync and it never returns a result. It just sits there and hangs. If I run the exact same code from a console app, it returns the result almost immediately. All of the code doing the work resides in a portable class library. I would appreciate any help you may be able to give. All of the other issues I have found on this state to use await client.PostAsync, which I am already doing. The code in my class library is as such:

Attaching httpHandler to httpclientFactory webapi aspnetcore 2.1

一笑奈何 提交于 2019-12-06 12:06:46
I am trying to attach an handler to httpclientfactory using "ConfigurePrimaryHttpMessageHandler" but when I look inside the HttpClient to see if the handler is there i cannot find it Am I attaching the handler correctly? Any Suggesions services.AddHttpClient<IGitHubClient,GitHubClient>(client => { client.BaseAddress = new Uri(myUri); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); }) .ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler { AllowAutoRedirect = false, AutomaticDecompression = DecompressionMethods.Deflate |

checking Internet connection with HttpClient

十年热恋 提交于 2019-12-06 10:41:17
问题 I am having difficulties to understand on how the bellow code could handle occasional internet connection loss. Ideally I would like to pause the app, once the connection is lost, and resume when it is up again. Is there any guideline on how to do it? HttpClientHandler clientHandler = new HttpClientHandler(); clientHandler.UseDefaultCredentials = true; HttpClient client = new HttpClient(clientHandler) { MaxResponseContentBufferSize = 1000000 }; HttpResponseMessage response = await client