Find Jobs
Hire Freelancers

Help with C# and HttpClient.PostAsync

$10-30 USD

Completed
Posted 5 months ago

$10-30 USD

Paid on delivery
Hi there I need some help with using [login to view URL] as not async. I always get blocking tasks and I dont know why ... Here is what I am trying: I have two functions, GetToken and Send. I can run GetToken and the Token is generated. As soon as I then run Send (Token, JsonString) with generated Token, Send gets blocked and never finishes. Below I send you the two methods. I think, for somebody who knows HttpClient well, it is some minutes of work. I cannot give a testable solution as the API url is not for public. And as this application is old style WinForms, I cannot use await. Best regards Frank Token _Token = [login to view URL](); var _Result = [login to view URL](_Token, [login to view URL]); public Token GetToken() { Dictionary<string, string> _Headers = new Dictionary<string, string> { {"grant_type", "client_credentials"}, {"scope", private_Scope}, {"client_id", private_ClientId}, {"client_secret", private_ClientSecret}, }; using ([login to view URL] _HttpClient = new [login to view URL]()) { using ([login to view URL] _HttpResponseMessage = [login to view URL]([login to view URL]("{0}{1}", private_TokenEndpoint, private_TokenEndpointExtension), new [login to view URL](_Headers)).GetAwaiter().GetResult()) { var _JsonContent = [login to view URL]().GetAwaiter().GetResult(); return [login to view URL]<Token>(_JsonContent); } } } public bool Send(Token _Token, string _JsonToSend) { using (MyHttpDelegatingHandler _MyHttpDelegatingHandler = new MyHttpDelegatingHandler(_Token)) { using ([login to view URL] _HttpClient = [login to view URL](_MyHttpDelegatingHandler)) { using ([login to view URL] _HttpResponseMessage = [login to view URL]([login to view URL]("{0}{1}", private_Endpoint, private_EndpointExtension), new StringContent(_JsonToSend, [login to view URL], "application/json")).Result) { string _ResponseMessage = [login to view URL]().GetAwaiter().GetResult(); if ([login to view URL]) { return true; } else { throw new Exception([login to view URL]("ERROR! Status code: {0}", [login to view URL], _ResponseMessage)); } } } } } public class Token { [[login to view URL]("access_token")] public string AccessToken { get; set; } [[login to view URL]("token_type")] public string TokenType { get; set; } [[login to view URL]("expires_in")] public int ExpiresIn { get; set; } } public class MyHttpDelegatingHandler : [login to view URL] { private readonly Token private_Token; private MyHttpDelegatingHandler() { } public MyHttpDelegatingHandler(Token _Token) { private_Token = _Token; } protected async override Task<[login to view URL]> SendAsync([login to view URL] _HttpRequestMessage, [login to view URL] _CancellationToken) { [login to view URL] = new [login to view URL]([login to view URL], [login to view URL]); [login to view URL] _HttpResponseMessage = await [login to view URL](_HttpRequestMessage, _CancellationToken); return _HttpResponseMessage; } }
Project ID: 37536190

About the project

9 proposals
Remote project
Active 5 mos ago

Looking to make some money?

Benefits of bidding on Freelancer

Set your budget and timeframe
Get paid for your work
Outline your proposal
It's free to sign up and bid on jobs
Awarded to:
User Avatar
Hi, try to change line : "application/json")).Result to "application/json")).GetAwaiter().GetResult(). Unfortunately, I can't check , but if GetToken works correctly and returns the value, that only one differents with Send.
$15 USD in 1 day
5.0 (7 reviews)
3.7
3.7
9 freelancers are bidding on average $20 USD for this job
User Avatar
Hi there, Can i have a look This is Fayiz, a full-stack engineer with over 9 years of experience in the IT industry. I have been delivering web, desktop and mobile development solutions successfully using various technologies, such as ASP .Net, .Net C#, MVC, .Net Rest API, .Net Core, Java, Java Spring Boot, PHP, Laravel, Android, HTML, JavaScript, CSS, Bootstrap, JQuery, Flutter, Angular, FNHibernate, Entity Framework, MS SQL, MySQL, PostgreSQL, Git, Docker, AWS, Azure, and Jenkins. With these skills, I can design/develop, customize, integrate, maintain, revamp, and optimize web, mobile and desktop applications for different platforms and domains. I am confident that I can handle this project efficiently and effectively. I always aim to offer a competitive budget without compromising on quality. I'm eager to collaborate and contribute to your project's success. Please feel free to contact me, I can start right away! Note: This is a placeholder bid. So, the Actual price and time will be given after a complete discussion. I hope to see you on my client list. Best regards, Fayiz Fareed
$10 USD in 1 day
5.0 (6 reviews)
4.1
4.1
User Avatar
Hello. I read your requirement and also check attached code i will do that. Please come on chat we will discuss more about this. I will waiting your reply.
$30 USD in 1 day
5.0 (4 reviews)
3.3
3.3
User Avatar
Hi , We hope this message finds you well. We have a team of experienced .NET C# developers with a background since 2018 in the field. We have carefully reviewed the initial project description you provided and we are excited to discuss further details regarding the timeline, budget, and specific requirements. Can we schedule a meeting to examine closely into the project requirements? This will allow us to discuss the details of the project, address any questions or concerns, and collaboratively establish a realistic timeline and budget. We are passionate about the opportunity to contribute our skills and expertise to your project. Looking forward to your positive response and the possibility of working together. Best regards, Team Code Frenzy
$10 USD in 3 days
4.8 (2 reviews)
3.1
3.1
User Avatar
I've already experienced this problem, and as I have knowledge and experience in this technology, I can contribute to your problem. I look forward to hearing from you
$20 USD in 2 days
0.0 (0 reviews)
0.0
0.0
User Avatar
Hi there With over 10 years of experience in different kinds of web and windows applications, my expertise span across full-stack development, expert in front-end and back-end technologies and especially in creating scalable and efficient solutions. Based on my experience, I am confident that I can sort out your issue in quick time. Send me a message to initiate your project.
$40 USD in 1 day
0.0 (0 reviews)
0.0
0.0

About the client

Flag of SWITZERLAND
Aesch LU, Switzerland
5.0
51
Payment method verified
Member since Nov 11, 2013

Client Verification

Thanks! We’ve emailed you a link to claim your free credit.
Something went wrong while sending your email. Please try again.
Registered Users Total Jobs Posted
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Loading preview
Permission granted for Geolocation.
Your login session has expired and you have been logged out. Please log in again.