Тёмный

Http Get And Post In C# 

Nick Proud
Подписаться 5 тыс.
Просмотров 92 тыс.
50% 1

Making an GET or POST Request is easy in C# thanks to the HttpClient object. See how you can build simple requests in .NET.
HTTP GET and HTTP POST are essential components of any web application, and this video will help you learn how to create a simple REST API using C#. By the end of this video, you'll be able to create a basic HTTP GET and HTTP POST REST API using C#.
If you're new to programming or want to learn more about the basics of the HttpClient library, this video is for you! By the end of the video, you'll be able to create simple HTTP GET and HTTP POST calls using C#, and understand the basics of the REST API. Thanks for watching!
For info on IDispose and the dispose pattern in C#, check out my blog post here:
#csharp #dotnet #programming #coding #softwaredevelopment #softwareengineering #coders #tutorials

Наука

Опубликовано:

 

7 июл 2021

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 154   
@atifakhtar3942
@atifakhtar3942 Год назад
year worth of university lectures in a 20 minutes. YOU ARE THE MAN.
@xsandwichxxsandwichx1778
@xsandwichxxsandwichx1778 Год назад
Not only did you explain it well, but you are super personable. I hope you have a lot of success with your RU-vid channel.
@nickproudprogrammer
@nickproudprogrammer Год назад
Thanks for the kind words! Really glad you found it useful. Please let me know if you have any requests for other specific content
@Cod3rMax
@Cod3rMax Год назад
Omg i love people like you who explain like this, simple code, everything is perfect thank you men
@nickproudprogrammer
@nickproudprogrammer Год назад
Pleasure!
@kizwiz6
@kizwiz6 2 года назад
That was a really good lesson and I learnt a lot. You explain things incredibly well and I hope you keep posting. *Subscribed.* .
@nickproudprogrammer
@nickproudprogrammer 2 года назад
Thanks! Really glad it helped and thanks for the sub! Let me know if there are any specific topics you'd like me to cover in future
@UnstoppablegamingNet
@UnstoppablegamingNet Год назад
I looked for weeks for a good and clean explanation of this, thank you so much. Please keep it up bud and again thank you so much.
@nickproudprogrammer
@nickproudprogrammer Год назад
My pleasure. I'm so glad it helped. Makes it all worth it!
@UnstoppablegamingNet
@UnstoppablegamingNet Год назад
@@nickproudprogrammer To give as much insight as I can to help from my noob self the step by step helps a lot, other videos out there gloss over too much because they know it so they think "I don't need to talk about it". I know a lot programing tends to be very abstract but the more visual the better just like most learn video games by pushing buttons and seeing what they do. I know this might be hard but info is power and thank you again :)
@TheDrHaze
@TheDrHaze 2 года назад
Thanks a lot, I've been trying to work with Api's for a while now. But I have never understand every step of the process. This is the first time I've found an explanation for each Expression and Statement.
@girmamoges941
@girmamoges941 Год назад
I admire such an explanation, to the core exactly what is needed in plain english. Extemely clear and valuable explanation, all the words from you when you explain are very important.
@nickproudprogrammer
@nickproudprogrammer Год назад
Thank you so much!
@Zenithix
@Zenithix 2 года назад
Thanks so much for the video, was really struggling with doing these HTTP requests since I've never done them before and this really helped out.
@nickproudprogrammer
@nickproudprogrammer 2 года назад
Glad it helped!
@izwansystec87
@izwansystec87 2 года назад
hi, thanks for the video. i looking for this almost 3hours
@eduard289
@eduard289 Год назад
Thanks. This is knowledge with explication for every possible click! I haven't been able to get it from anybody else ! Thank you a lot !
@nickproudprogrammer
@nickproudprogrammer Год назад
You're welcome!
@munsoninuk
@munsoninuk 2 года назад
Very good lesson as explained very clear.
@brainache7630
@brainache7630 2 года назад
Well, again some random guy rescues the day. :D Thanks man! That was exactly what i was looking for.
@nickproudprogrammer
@nickproudprogrammer 2 года назад
My pleasure! Hope I can help you out again in future
@mlong30
@mlong30 Год назад
Just what I needed for my client. Just needed to add the SecurityProtocol and I was all set. Thanks again!
@nickproudprogrammer
@nickproudprogrammer Год назад
Great to hear!
@cuongme626
@cuongme626 Год назад
Mate, it’s bad practice to wrap HttpClient in a Using statement and definitely shouldn’t be implemented in production code.
@salilshukla2686
@salilshukla2686 Год назад
Thanks . My concept got more clearer.
@waqarali4563
@waqarali4563 2 года назад
Guide how to post Authorized Api which required header and detail as RawBody format
@juliakreikenbaum1744
@juliakreikenbaum1744 Год назад
Very helpful! Thank you!
@aviko9560
@aviko9560 Месяц назад
Thank you very much, great video and exactly what I needed!
@uniquedesign5680
@uniquedesign5680 2 года назад
Hi, Thanks for the nice tutorial. How should I add multiple headers in the request?
@mesh475
@mesh475 Год назад
You Got sent amazing man. Thanks =)
@AsharMalik-oo9nz
@AsharMalik-oo9nz 2 месяца назад
This is super http client explanation It took me 2 years and 20 mins to understand it you did it in 20 mins
@PhilCroucher
@PhilCroucher Год назад
Thanks Nick, just what I was looking for. The Async bit was catching me out, the .Result was the missing bit for me.
@nickproudprogrammer
@nickproudprogrammer Год назад
My pleasure! I'm glad it was useful :)
@JohnatanDoe
@JohnatanDoe Месяц назад
Thank you, brother, you helped me figure out a lot.
@Maneki-Nico
@Maneki-Nico Год назад
That was such a good explenation that even a Python bro could understand it (me). Thnx mate cheers
@nickproudprogrammer
@nickproudprogrammer Год назад
Haha! Glad you liked it
@marcellapetrucci7029
@marcellapetrucci7029 2 года назад
That was a really great explanation, thank you! I have struggled with this for a while and I am currently working on a student project to write a simple client / server application using http protocol but instead of serving to a url / web client I am just updating an object in a local datastore. Is it possible to adapt this tutorial to suit those needs? And if so, would you consider adding some examples of that to this project? Thanks again
@nickproudprogrammer
@nickproudprogrammer 2 года назад
Hi! Thanks for the kind feedback! I'm not sure I fully understand your use case. Could you provide some more detail on what you're trying to achieve? Then I could look at making something for you :)
@simonmunozbaldo7583
@simonmunozbaldo7583 2 года назад
Really helpfull, thank you buddy
@IsraelAlvesLucena
@IsraelAlvesLucena Год назад
Man... You just saved me... I'm here the whole day at that dumb part of the code just for get a simply json back from a API. The more I learn other programming languages, more I love Python... Sorry for that. But thank you!
@nickproudprogrammer
@nickproudprogrammer Год назад
You're so welcome, and I'm so glad this helped 😁
@user-gm2ps2wl1m
@user-gm2ps2wl1m 7 месяцев назад
very good lesson for the beginners. Thanks!
@nickproudprogrammer
@nickproudprogrammer 6 месяцев назад
You're very welcome!
@weamhaleemi4984
@weamhaleemi4984 Год назад
very helpful thanks !
@ibrahimhammed4176
@ibrahimhammed4176 5 месяцев назад
Thanks, Nick, for posting this excellent video. It is really helpful to me.
@nickproudprogrammer
@nickproudprogrammer 5 месяцев назад
Thank you so much for your kind words! I'm glad to hear that the video was helpful to you. If you have any other topics you'd like me to cover, let me know!
@belmiris1371
@belmiris1371 Год назад
Thanks for this.
@addisonzoraoffical
@addisonzoraoffical 2 года назад
Thanks, code works well
@Yes.Im.Mr.Anderson
@Yes.Im.Mr.Anderson 6 месяцев назад
Absolutely brilliant explanation!
@nickproudprogrammer
@nickproudprogrammer 6 месяцев назад
Many thanks!
@brgule021
@brgule021 2 года назад
Excellent!!!
@samayazghulam-e-mustafa7169
keep going man.nice tutorial
@nickproudprogrammer
@nickproudprogrammer Год назад
Thanks, will do!
@wegene2056
@wegene2056 2 года назад
thanks for a clear explanation.
@nickproudprogrammer
@nickproudprogrammer 2 года назад
You are welcome!
@prajwalrangegowda
@prajwalrangegowda 9 месяцев назад
Very clearly explained Thank you!
@nickproudprogrammer
@nickproudprogrammer 8 месяцев назад
Thank you! Glad it was helpful 👍
@lanceawatt
@lanceawatt 2 года назад
Awesome, really informative
@nickproudprogrammer
@nickproudprogrammer 2 года назад
Glad it was helpful!
@Pedroramossss
@Pedroramossss 2 года назад
Hi Nick. Thank you very much for the vídeo. I have a question. Looking at The string at 9 minutes in the vídeo. Let's say I want to put objects with these attributes in a list. How would I do that?
@Todd82TA
@Todd82TA Год назад
Thank you!
@nickproudprogrammer
@nickproudprogrammer Год назад
You're welcome!
@tanyasrivastava7969
@tanyasrivastava7969 6 месяцев назад
Very clear explanation great video and easy to understand...👌🏻👌🏻👌🏻
@nickproudprogrammer
@nickproudprogrammer 6 месяцев назад
Thanks a lot 😊
@EdRawrDev5813
@EdRawrDev5813 Год назад
great music 💜💀💎
@w97802
@w97802 Год назад
Thank you for the wonderful explanation! May I ask why would you choose ".Result" instead of "await" here?
@nickproudprogrammer
@nickproudprogrammer Год назад
If you wanted to run the method synchronously, then you'd use .Result like I did, and really, this was just for the video to keep my code running easily for debug. In practice, I would use await by default.
@HemmingEducation
@HemmingEducation Год назад
Awesome!
@jeffreydijkstra3391
@jeffreydijkstra3391 2 года назад
really helpfull, thanks my guy
@nickproudprogrammer
@nickproudprogrammer 2 года назад
My pleasure! Thanks for watching. I'm really glad it helped and I hope I can help again :)
@mohamedkunle528
@mohamedkunle528 Год назад
Thank you so much
@IslamAudioStation
@IslamAudioStation 2 года назад
This is cool.
@oscargomez-yk8tp
@oscargomez-yk8tp Год назад
Thanks!
@nickproudprogrammer
@nickproudprogrammer Год назад
Hey thank you for the super thanks! Appreciate ya 🙏
@Mathias-cq3zo
@Mathias-cq3zo Год назад
Can I use this method using WPF? thanks in advanced!!
@slavkodjakovic2670
@slavkodjakovic2670 2 года назад
That was a really great explanation, thank you!, thank you! Could you show an example how to upload xml file to endpoint? Thank you.
@nickproudprogrammer
@nickproudprogrammer 2 года назад
Funny you should ask, there is a mention on how to do this in a video I'm releasing next week on Wednesday. Stay tuned!
@slavkodjakovic2670
@slavkodjakovic2670 2 года назад
@@nickproudprogrammer Thank you!
@mebtuabebe8428
@mebtuabebe8428 Год назад
That is a very good lesson. Thank you very much.
@salvadortascon1753
@salvadortascon1753 Год назад
Great video Thanks a lot I only have one question How can I post an already existing json file using this post method ?
@nickproudprogrammer
@nickproudprogrammer Год назад
Use the System.IO namespace to read the json file as text. System.IO.File.ReadAllText(yourFilePath) Then use that text as the payload with Content-Type set to 'application/json'
@chuka4901
@chuka4901 Год назад
You should not use HttpClient with an using statement. Otherwise it could cause a SocketException due to Socket Exhaust.
@mirko290577
@mirko290577 Год назад
Hi, tks for video...I would like a question. If Post Class has three property(Title, Body and UserId), what represents "id":101? { "Title": "Test Post", "Body": "Hello World!", "UserId": 44, "id": 101 } Tks for answers...
@sinanatairmak1839
@sinanatairmak1839 8 месяцев назад
very good video heres a like !
@nickproudprogrammer
@nickproudprogrammer 8 месяцев назад
Thank you!
@mffarooqpk
@mffarooqpk 2 года назад
great learning. very thank you. one question about i got stuck is that how to get only id value like 101 from this return result set at 18:49 video time. plz guide.
@nickproudprogrammer
@nickproudprogrammer 2 года назад
You can use NewtonSoft Json for this with JObject.Parse. Take a look at this link. It would be JObject.Parse("id").ToString() www.newtonsoft.com/json/help/html/m_newtonsoft_json_linq_jobject_parse.htm
@TheMilliardo
@TheMilliardo 2 года назад
Could you show an example with authentification? I'm trying for a while to log into Magento 2 with admin token ... Nothing helps, even stackoverflow.
@nickproudprogrammer
@nickproudprogrammer 2 года назад
What is the name of the token header you need to send? Are you using any specific Magento api documentation?
@sunindragupta9236
@sunindragupta9236 2 года назад
I need to set a cookie on the Get request, can you please help
@jinkijung6401
@jinkijung6401 Год назад
Hi Nick Thank you for your simple but powerful explanation. I am trying to follow your code to connect with Bearer token, but don't know where to put the Token information. Can you please show me where and how to call it. Thank you again
@nickproudprogrammer
@nickproudprogrammer Год назад
You should be able to set the 'Authorization' property of the http client's 'DefaultRequestHeaders' as below. (Remember to either use a HttpClientFactory or static HttpClient and NOT a using statement. This prevents port exhaustion). - and obviously ensure your client is disposed of when you're finished with it 👍 var client = new HttpClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "Your token");
@imaneaiani4040
@imaneaiani4040 2 года назад
Hello Nick, thank you for the video, very good explanation. But as my url is authenticated as bearer token, how can I do that ?
@nickproudprogrammer
@nickproudprogrammer 2 года назад
Depends on how it's expecting the token to be sent. Do you have documentation for your API or is it publicly available? Or is it private?
@imaneaiani4040
@imaneaiani4040 2 года назад
@@nickproudprogrammer Unfortunatly, I don't have any documentation about it. But I have managed to solve it. I have used the Dictionary and it worked. Thank you again
@loc4478
@loc4478 10 месяцев назад
Im not sure if you are still checking the comments on this but I saw somewhere else someone talking about not putting your HTTP client in a using statement cause "it isn't the kind of object you want to instanciate a lot" but you are saying that you should. Could you elaborate if one of these ways is better
@sayedziamohammadi2694
@sayedziamohammadi2694 Год назад
The Best
@garciablancocesar
@garciablancocesar Год назад
Hi Nick! I've been struggling with getting a json from an api, could you please help me?
@nickproudprogrammer
@nickproudprogrammer Год назад
Sure. Are you getting an error message? Send some details of the issue via my website and I'll take a look - www.automationmission.com/contact/
@greatred2558
@greatred2558 2 года назад
Thanks
@nickproudprogrammer
@nickproudprogrammer 2 года назад
No problem
@matthewkeen6281
@matthewkeen6281 Год назад
nice
@nickproudprogrammer
@nickproudprogrammer Год назад
Thanks
@user-vx5hf8nb8s
@user-vx5hf8nb8s Год назад
If we can't see Post.cs, give link to source code please
@tahapek2411
@tahapek2411 Год назад
How to add authenticate while posting process Coudl you explain that please
@nickproudprogrammer
@nickproudprogrammer Год назад
Depends on the authentication type in use. What are you using? Basic, OAuth? etc
@tupalexlopez2813
@tupalexlopez2813 Год назад
how get a IMG in C# with the method GET?
@nickproudprogrammer
@nickproudprogrammer Год назад
Depends on the API. Would need more info. Send some details of the issue via my website and I'll take a look - www.automationmission.com/contact/
@judgedev2789
@judgedev2789 2 года назад
How i read Active html with c#? For example when i login to the website i want to get html
@nickproudprogrammer
@nickproudprogrammer 2 года назад
You should be able to use a GET request on any url to get the html content. Then you could use something like the HTMLAgilityPack to parse the returned HTML html-agility-pack.net/
@judgedev2789
@judgedev2789 2 года назад
@@nickproudprogrammer i already used that agility package but it just reading First html content
@judgedev2789
@judgedev2789 2 года назад
@@nickproudprogrammer cant i read active Google Chrome html content ? Is it possible
@nickproudprogrammer
@nickproudprogrammer 2 года назад
@@judgedev2789It's tricky with google, because http requests usually end up being shown the initial 'consent' window. You may want to look into an RPA solution like UIPath to automate getting through the google search page and then scraping the html
@judgedev2789
@judgedev2789 2 года назад
@@nickproudprogrammer thanks man i will look into it
@garudakurt5166
@garudakurt5166 2 года назад
How to deserialze json to c# object ?
@nickproudprogrammer
@nickproudprogrammer 2 года назад
Great suggestion. I'll be making a video on this soon
@garudakurt5166
@garudakurt5166 2 года назад
@@nickproudprogrammer thanks sir but I need it badly. I tried all youtube tutorial even in google and stack overflow. But none of them work with my code. I hope you will upload asap for my thesis project.
@garudakurt5166
@garudakurt5166 2 года назад
I already figure out thanks anyway sir nick!
@nickproudprogrammer
@nickproudprogrammer 2 года назад
@@garudakurt5166 great! Glad you're all set
@alexanderstroustrup4427
@alexanderstroustrup4427 Год назад
It's support TLS 1.3?
@nickproudprogrammer
@nickproudprogrammer Год назад
Should do, but if you need to specify specific TLS version: System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls13
@dasmaffin1633
@dasmaffin1633 Год назад
So everything in your lesson works for me, but when I try to reach my own endpoint it results in an error 400, but the demo automatically generated with swagger works, wtf
@nickproudprogrammer
@nickproudprogrammer Год назад
Are you sending a payload of some sort? If so is it valid? Might be the difference between what you're doing from scratch and within Swagger
@rodrigomoro8047
@rodrigomoro8047 Год назад
Hello Nick, amazing tutorial. Yet I'm getting the following result response: Id = 19, Status = WaitingForActivation, Method = "{null}", Result = "{Not yet computed}" Any clues on the solution of that?
@nickproudprogrammer
@nickproudprogrammer Год назад
Sounds like you're calling an async method without awaiting it. Use await or if you want to run it synchronously, use .Result at the end of the method
@rodrigomoro8047
@rodrigomoro8047 Год назад
@@nickproudprogrammer worked like a charm, thanks a lot!
@nickproudprogrammer
@nickproudprogrammer Год назад
@@rodrigomoro8047 Great!
@radosawberlinski2567
@radosawberlinski2567 10 месяцев назад
Blog post link doesn't work.
@soreyrothkong3027
@soreyrothkong3027 2 года назад
HI it worked well many thanks for this video but my code shows an error System.Net.WebExceptiom. The remote server returned an error. I think it needs the code username and password? cus my API has a username & password can u do a video of it or provide the source code pls?
@nipun384
@nipun384 Год назад
WHATS VAR NEWPOST = NEW POST()
@cuongme626
@cuongme626 Год назад
Although HttpClient implements IDisposable you SHOULD NOT wrap it within an Using statement. In fact, it is extremely BAD practice to do this as connections aren’t released straight away which can cause network exhaustion and DNS issues when called in high volumes. The correct way to use HttpClient is reusing it with HttpClientFactory. It saddens me that so many programmers do not know how to use HttpClient properly and why it shouldn’t follow the IDisposable pattern. What’s worst are people commenting that it’s a great video, implement it and unaware that it’s incorrect and bad practice.
@tuyentuyen2061
@tuyentuyen2061 Год назад
hi
@tuyentuyen2061
@tuyentuyen2061 Год назад
hello
@tuyentuyen2061
@tuyentuyen2061 Год назад
dd
@tuyentuyen2061
@tuyentuyen2061 Год назад
ddd
@tuyentuyen2061
@tuyentuyen2061 Год назад
ssss
@tuyentuyen2061
@tuyentuyen2061 Год назад
xxxx
@tuyentuyen2061
@tuyentuyen2061 Год назад
fddf
@2thelimit630
@2thelimit630 Год назад
the use of var is WAY TO MUCH
@agentstona
@agentstona 2 года назад
dafuq you wasted 19.36 minutes of my life to explain something that could be done in under 5 minutes ............GET GOOD SON
@Troyjl_3
@Troyjl_3 Год назад
this video as helped me a lot and I was able to do both get and post request with already created endpoints. Thank you! I am working on something new and am using your POST method but I am getting the error back {"detail":"Authentication credentials were not provided."} I am trying to send a POST request to get a bearer token back. and the javascript they sent me looks as follows; any suggestions? also under my headers in postman for KEY: Authorization it then has VALUE: Basic kdfjjsdfASDFASD34234DASd== So am not sure how I would send that Basic Auth to return the client_credentials pm.sendRequest( { "url": `${base_url}/quote/auth`, "method": 'POST', "header": { "Content-Type": "application/json", "Authorization": `Basic ${btoa(basic_auth_cred)}`, }, "body": { "mode": "raw", "raw": JSON.stringify({ "auth_type": "client_credentials", }), } }, function (err, response) { const response_data = response.json(); if (response_data.access_token === undefined) { throw new Error("No access token recieved."); } pm.request.headers.add({ name: "Authorization", key: "Authorization", value: `Bearer ${response_data.access_token}`, }); } );
@Troyjl_3
@Troyjl_3 Год назад
Actually with your video and one online source I was able to get the client credentials back! Thank you for this video!! Now that I have the bearer token, I am going to have to do a GET request using the bearer token to a new endpoint.
@nickproudprogrammer
@nickproudprogrammer Год назад
Amazing!
@zero_wing_
@zero_wing_ Год назад
Really bad tutorial if you have to use another REST Framework that basically does all the work for you. Really should be called how to Post in Newtonsoft.
@cuongme626
@cuongme626 Год назад
Not just that. Wrapping HttpClient in an Using statement is NO, NO, NO.
@andreiffllooo07
@andreiffllooo07 11 месяцев назад
Thank you!
@nickproudprogrammer
@nickproudprogrammer 11 месяцев назад
Very welcome!
@Renanmromeo
@Renanmromeo 2 года назад
Awesome!
@nickproudprogrammer
@nickproudprogrammer 2 года назад
Thank you! Cheers!
@tuyentuyen2061
@tuyentuyen2061 Год назад
ssss
@tuyentuyen2061
@tuyentuyen2061 Год назад
ssss
Далее
Игровой Комп с Авито за 4500р
01:00
Angular HTTP Client Quick Start Tutorial
9:56
Просмотров 192 тыс.
Brutally honest advice for new .NET Web Developers
7:19
Using HttpClient in .NET Core to Connect to APIs in C#
45:03
Blazor in 100 Seconds
2:33
Просмотров 549 тыс.
tRPC, gRPC, GraphQL or REST: when to use what?
10:46
Просмотров 71 тыс.
How To Call a REST API In Java - Simple Tutorial
29:14
Просмотров 258 тыс.
Will the battery emit smoke if it rotates rapidly?
0:11
Дорогие компы БЕСПОЛЕЗНЫ?
1:00
Просмотров 738 тыс.