https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_b964594d3d957944241961017b9eb19bf02834de44cce93d8e67dd306852dbe346167181e455e33d5268ea01d973d77bb056848546f31794f31a4c31a9da5aa3.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_09f62869dbd00446535ebe8e270406331e6f0ae459deba58094caeadc22d58825ffc99f8c217b496ec112cbb1da8b662d77b0f52eae24cc5631f95695e40d87b.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_71df4b601e09aaa66a8c630d70a95f93ec4b4e87d200ef58395a187ef9b932190b6a6160b44a7c23698d60d669499051093da9bb0b8343bc0a1ed3fe002dccc3.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_e6b7e0bf68aa4a61d5c6a0065ec42e38a0cc53e39a4fbee057b72d4b2297b37c01e716e1e61bac7f240b5a0edbb178d37b62f7ed4ea4ea3d10e46dbe7429f326.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_bfff9e63e857e9ee612e292d4a6edf3ced64d6a756925c953a9d8f77845ff601eca64d73dfa48756b1a9f4a4d6de6127a273bcde16ddeb71a22383460f4e94b0.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_f4dd7e1d73ae5eda35ed5ad6aa965b612dbf483ece3ca50c1e8e30ad8dff1c66a160ed75e958e2db399661d229874783e0834ad813a479437035666b8e9e3386.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_4fce0769137d4cd096989b0349bc3c2bbfca79ac311fdf714c41ab24d87551c7b49b756c8a8de090b0714a0ad0560e49fa532ba5a88875ea4afd78efac464df6.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_85cec8b07d60426b11040e471babca0d2f9c8dc87a9b56e06cad39828f7f67179e29609100f282a574872c9a93fb635b25416300eb4c97bc5a653d00cf6f8dbf.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_6768e5a27d4d357347338621c0d20bd269b126d30eec796193390f2f530fbaea60af84130c46f9786114be65149e661e87d55c339219c90aa76396d7e5b734ef.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_2acd6bdff3b680341e8c727da5169a647123eb8fd0a90253161b4c3af272c15d293bf9bb217008bb13f84d1910b0e166798001f8603b6c026d5c20a76c41d47c.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_8a0f35805486a30d9d6c1226e6b4247970730af5e476401552587a54e7ebff2c9fba7060f254434fa3934d74c8f72a431752411defea8c0a6172cd8838b4a274.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_268c9bba6ba649318f0da28c37b09a9bbfa371210f9b6b52faa7fd8ae94abf6b3c3bfeb5df5705c93495ce1152ca58aeabc435d6c6c1bd959025165c3f50e086.js
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • Featured
    • Advanced Python Topics
    • AWS Learning Roadmap
    • JWT Complete Guide
    • Git CheatSheet
  • Explore
    • Programming
    • Development
      • microservices
      • Front End
    • Database
    • DevOps
    • Productivity
    • Tutorial Series
      • C# LinQ Tutorials
      • PHP Tutorials
  • Dev Tools
    • JSON Formatter
    • Diff Checker
    • JWT Decoder
    • JWT Generator
    • Base64 Converter
    • Data Format Converter
    • QR Code Generator
    • Javascript Minifier
    • CSS Minifier
    • Text Analyzer
  • About
  • Contact
CodeSamplez.com

CodeSamplez.com

Programming And Development Resources

You are here: Home / Programming / C# HTTP Requests Tutorial For Beginners

C# HTTP Requests Tutorial For Beginners

Updated April 23, 2025 by Rana Ahsan 46 Comments ⏰ 7 minutes

C# HTTP Requests For Beginners

Hey there! Ever wondered how your C# app can chat with a web server? That’s where HTTP requests swoop in to save the day. Whether you’re grabbing data from a REST API or sending stuff to a server, HTTP requests are your go-to tool. In this post, I’m diving into the best way to make C# HTTP requests using the mighty HttpClient class.

This article is updated for .NET 6 and Later. Reference to old code in case anyone is looking for. Cheers!

What Are HTTP Requests, Anyway?

First off, HTTP requests are how your app talks to the internet. Simple as that. You send a message—like “Hey, gimme some data!”—and the server replies. Back in the day, folks used clunky stuff like WebRequest, but that’s old news. Today, HttpClient is the king of C# HTTP requests. It’s fast, slick, and plays nice with async/await, which keeps your app snappy. Stick with me, and I’ll show you how to wield it like a pro.

FAQ: What’s the best way to make HTTP requests in C#?

Use HttpClient. It’s the modern, no-nonsense choice for rock-solid, asynchronous requests. We will explore both this and wrapper-library-based examples.

Setting Up Your C# Playground

Before we dive into the code, let’s set up shop. You’ll need .NET 6 or later—trust me, it’s worth it for the slick features and cross-platform goodness. Not sure what you’ve got? Open your terminal and type dotnet –version. If it’s below 6, head to dotnet.microsoft.com/download and snag the latest version. Done? Awesome.

Now, let’s whip up a new project. Fire up your terminal and run:

dotnet new console -n HttpRequestsDemo
cd HttpRequestsDemoCode language: JavaScript (javascript)

Boom! You’ve got a shiny new console app ready to roll. Open it in your favorite editor (I’m a Visual Studio Code fan myself), and let’s start coding some C# HTTP requests.

Making Your First GET Request

Alright, let’s kick things off with a GET request. This is how you fetch data—like grabbing a blog post from a server. We’ll use a free API called JSONPlaceholder to test this out. It’s perfect for beginners and won’t bite. Here’s the code to get you started:

using System;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static async Task Main(string[] args)
    {
        using var client = new HttpClient();
        var response = await client.GetAsync("https://jsonplaceholder.typicode.com/posts/1");
        var content = await response.Content.ReadAsStringAsync();
        Console.WriteLine(content);
    }
}Code language: JavaScript (javascript)

Run that bad boy with dotnet run, and you’ll see some JSON magic flood your console. Cool, right? Let’s break it down:

  • The HttpClient Line: I create one HttpClient instance here. This guy’s reusable—don’t keep making new ones, or you’ll clog up your app’s sockets. More on that later.
  • The GetAsync Call: This sends a GET request to our URL. It’s async, so await keeps things smooth without freezing your app.
  • Reading the Response: We grab the content as a string and print it. Easy peasy.

FAQ: How do I make a GET request in C#?

Use HttpClient.GetAsync With a URL, await the response, and read the content. Done.

Handling That Response Like a Boss

Okay, so you’ve got a response. Now what? Servers don’t always play nice, so you gotta check if things went smooth. Here’s how to handle it:

var response = await client.GetAsync("https://jsonplaceholder.typicode.com/posts/1");
if (response.IsSuccessStatusCode)
{
    var content = await response.Content.ReadAsStringAsync();
    Console.WriteLine("Sweet! Here’s the data: " + content);
}
else
{
    Console.WriteLine($"Oops, something’s off. Status: {response.StatusCode}");
}Code language: JavaScript (javascript)

See that IsSuccessStatusCode check? It’s your best friend. If the status code is in the 200s (like 200 OK), you’re golden. Otherwise, you’ll know something’s up—like a 404 Not Found or a 500 Server Error. This keeps your app from choking on bad responses.

Sending Stuff with a POST Request

Now, let’s flip the script and send data with a POST request. Say you’re creating a new post on a server—this is how it’s done. Check this out:

var postData = new StringContent(
    "{\"title\":\"foo\",\"body\":\"bar\",\"userId\":1}",
    System.Text.Encoding.UTF8,
    "application/json"
);
var response = await client.PostAsync("https://jsonplaceholder.typicode.com/posts", postData);
if (response.IsSuccessStatusCode)
{
    var content = await response.Content.ReadAsStringAsync();
    Console.WriteLine("Post created! Here’s the response: " + content);
}
else
{
    Console.WriteLine($"Dang it, failed with: {response.StatusCode}");
}Code language: JavaScript (javascript)

Here’s the scoop:

  • The StringContent Part: This is your data, formatted as JSON. We tell it to use UTF-8 encoding and set the content type to application/json so the server knows what’s up.
  • The PostAsync Call: Sends that data to the server. Await it, and you’re good.
  • Checking Success: Same deal as before—make sure it worked.

FAQ: How do I make a POST request in C#?

Use HttpClient.PostAsync With your data wrapped in StringContent. await The response and check if it’s successful.

Catching Errors Before They Wreck You

Real talk: stuff breaks. Servers crash, networks flake, and typos happen. You need to armor up with error handling. Here’s how I do it:

try
{
    var response = await client.GetAsync("https://jsonplaceholder.typicode.com/posts/1");
    response.EnsureSuccessStatusCode(); // Throws if it’s not a success
    var content = await response.Content.ReadAsStringAsync();
    Console.WriteLine(content);
}
catch (HttpRequestException ex)
{
    Console.WriteLine($"HTTP meltdown: {ex.Message}");
}
catch (Exception ex)
{
    Console.WriteLine($"Total chaos: {ex.Message}");
}Code language: JavaScript (javascript)

That EnsureSuccessStatusCode method? It’s a beast—it’ll throw an exception if the status isn’t in the 200s, so you don’t miss a beat. Wrap it in a try-catch, and you’ll catch nasty surprises like network timeouts or bad URLs. Trust me, this saves headaches.

Best Practices to Follow:

Alright, you’re making C# HTTP requests like a champ. But let’s polish it up with some pro tips:

  • Reuse HttpClient: Don’t create a new one every time—it’s a resource hog. One instance, used forever, is the way to go. In our console app, we did it right with using var client.
  • ASP.NET Core Bonus: If you’re building a web app, use IHttpClientFactory. It’s a factory that churns out HttpClient instances, handling all the messy stuff like connection pooling. Look it up when you’re ready—it’s a game-changer.
  • Set a Timeout: Add client.Timeout = TimeSpan.FromSeconds(30); to avoid hanging forever if the server’s napping.

These habits keep your app lean, mean, and ready for action.

RestSharp Library: The Fancy Alternative

Back in 2016, folks loved RestSharp, and it’s still kicking. It’s a slick wrapper around HttpClient that makes REST calls feel like a breeze. Here’s a taste:

using RestSharp;

var client = new RestClient("https://jsonplaceholder.typicode.com");
var request = new RestRequest("posts/1", Method.Get);
var response = await client.ExecuteAsync(request);
Console.WriteLine(response.Content);Code language: JavaScript (javascript)

It’s shorter and sweeter, handling JSON and stuff for you. But honestly? HttpClient does the job fine without extra baggage. Your call—stick with the built-in power or grab RestSharp for some flair.

Wrapping It Up

There you have it, folks! You’ve mastered C# HTTP requests with HttpClient. We’ve tackled GET and POST requests, tamed errors, and sprinkled in some best practices. You’re ready to hit the ground running. Go mess around with APIs—try fetching weather data or posting tweets (well, fake ones on JSONPlaceholder). The world’s your oyster now.

Got questions? Drop ‘em below. Happy 👀 #️⃣ coding!

Share if liked!

  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on X (Opens in new window) X
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to share on Tumblr (Opens in new window) Tumblr
  • Click to share on Pocket (Opens in new window) Pocket

You may also like


Discover more from CodeSamplez.com

Subscribe to get the latest posts sent to your email.

First Published On: December 21, 2010 Filed Under: Programming Tagged With: .net, c#, http

About Rana Ahsan

Rana Ahsan is a seasoned software engineer and technology leader specialized in distributed systems and software architecture. With a Master’s in Software Engineering from Concordia University, his experience spans leading scalable architecture at Coursera and TopHat, contributing to open-source projects. This blog, CodeSamplez.com, showcases his passion for sharing practical insights on programming and distributed systems concepts and help educate others.
Github | X | LinkedIn

Reader Interactions

Comments

  1. Naim says

    March 19, 2011 at 4:21 AM

    I am trying to make call to pages in facebook Graph API and retrive in my application. Do you suggest me to go through install Facebook C# SDK or to use the code above for accessing.

    Kind regards,
    Naim

    Reply
    • Rana says

      March 21, 2011 at 5:06 AM

      Depends on the spec domain. If you are creating an fully Facebook based application, then I will suggest you to use the facebooksdk. For simple usage(and to understand better how they works), you can go with the manual approaches that i have discussed in few posts. Hope this helps.

      Reply
      • gokila says

        July 30, 2013 at 9:18 PM

        i need how to connect with user and server

        Reply
  2. Phil says

    April 3, 2011 at 5:36 PM

    Hi Rana,

    Thanks for you post.
    I had a error at line 57 dataStream = request.GetRequestStream();
    The error msg is “Cannot send a content-body with this verb-type”
    Is there any extra I need to do?
    Thanks

    Warm Regards
    Phil

    Reply
    • swamy says

      October 31, 2012 at 5:51 AM

      enter the method name as “POST”

      Reply
  3. jason says

    April 6, 2011 at 1:45 AM

    GET method does not work.

    The error msg is “Cannot send a content-body with this verb-type”

    Reply
  4. Daniel says

    April 17, 2011 at 7:56 AM

    what if I want to call a javascript function on a page?
    like:

    httpget(uri, “javascript:ChangeAcc()”);

    happy programming 🙂

    Reply
  5. janmu says

    June 8, 2011 at 2:50 AM

    Modification for GET request working

    public MyWebRequest(string url, string method, string data)
    : this(url, method)
    {

    if (request.Method == “POST”)
    {
    // Create POST data and convert it to a byte array.
    byte[] byteArray = Encoding.UTF8.GetBytes(data);

    // Set the ContentType property of the WebRequest.
    request.ContentType = “application/x-www-form-urlencoded”;

    // Set the ContentLength property of the WebRequest.
    request.ContentLength = byteArray.Length;
    // Get the request stream.
    dataStream = request.GetRequestStream();

    // Write the data to the request stream.
    dataStream.Write(byteArray, 0, byteArray.Length);

    // Close the Stream object.
    dataStream.Close();
    }
    else
    {
    String finalUrl = string.Format(“{0}{1}”, url, “?” + data);
    request = WebRequest.Create(finalUrl);

    WebResponse response = request.GetResponse();

    //Now, we read the response (the string), and output it.
    dataStream = response.GetResponseStream();
    }

    }

    Reply
    • Максим Киселёв says

      December 15, 2014 at 7:46 PM

      thank you

      Reply
  6. asif says

    July 26, 2011 at 12:51 AM

    Dear Sir,
    I have 2 doubts

    1. I am not getting should I use same url or replace it to my domain url which I dont have.
    http://www.yourdomain.com

    2.
    Getting error at below line
    public string GetResponse()

    {

    // Get the original response.

    WebResponse response = request.GetResponse();

    Error is
    WebException was unhandled by user code
    “The remote server returned an error: (405) Method Not Allowed.”

    Kindly help me to resolve it.

    Reply
  7. Jack says

    January 25, 2012 at 6:43 AM

    How would you implement it using a username and password?

    Reply
  8. keerthy says

    March 5, 2012 at 4:45 AM

    how do i close the connections immediately? i am getting the 4 instances ….

    Reply
  9. ftf says

    April 26, 2012 at 8:22 AM

    it is not necessary to close a stream when you’ve already called Close() on its assigned StreamWriter/Reader. it does it for you automatically.

    it’s also a good practice to use the “using” keyword when working with streams.
    for instance if we have a stream ‘s’ and string ‘stuff’

    using (StreamWriter sw = new StreamWriter (s) )
    {
    sw.Write (stuff);
    }

    once the end of the block is reached, the StreamWriter object gets disposed, calling Close() on itself before that happens and in turn closing the underlying stream as well.

    I’m using the following convenience methods to write to and read from streams when working with http requests, feel free to use them yourself.

    public static void StringToStream(Stream stream, string content)
    {
    using (StreamWriter writer = new StreamWriter(stream))
    {
    writer.Write(content);
    }
    }

    public static string StringFromStream(Stream stream)
    {
    string content;
    using (StreamReader reader = new StreamReader(stream))
    {
    content = reader.ReadToEnd();
    }
    return content;
    }

    Reply
  10. John Bradford says

    July 26, 2012 at 3:32 AM

    How do i post and retrieve data to/fro a remote MS SQL using the this http webserver

    Reply
  11. Trevor McIntire says

    August 11, 2012 at 10:04 AM

    Hello. I’m getting:
    Cannon implicitly convert type ‘MyWebRequest’ to ‘System.Net.WebRequest’, On WebRequest myRequest = new MyWebRequest(“http://www.minecraft.net”,”POST”,”a=value1&b=value2″);

    Reply
  12. Eric Collins says

    August 28, 2012 at 7:41 AM

    It would be very helpful to see what ‘using’ statements you would need in both the example code and the class that you created.

    I find so many examples were people give code but do not give the using statements to know which areas of the .net library to call. This would be extremely helpful for people are are just starting out and don’t have common library’s or using statements memorized.

    Thank you

    Reply
  13. Andy says

    January 15, 2013 at 12:46 AM

    Can you please elaborate how to run this program in vs
    Also is it necessary to install IIS to run this program?

    Reply
    • Md. Ali Ahsan Rana says

      January 15, 2013 at 2:13 AM

      You can run it on either a desktop application or on web application. This will facilitate you in cases, where your application itself need to request to other external web http get or post request and process the response. You don’t need to install iis.

      Reply
  14. Leandro Farias says

    January 21, 2013 at 7:17 AM

    Hi, im need get one request of another website, they send to me via POST, but i dont know how i get in my page, they send 2 parameters:
    Like that: notificationCode=766B9C-AD4B044B04DA-77742F5FA653-E1AB24
    notificationType=transaction

    Im using C#

    What i go put on pageload to get this parameters?

    Thanks for all help.

    Reply
    • Md. Ali Ahsan Rana says

      January 22, 2013 at 4:18 AM

      Hi, you can handle them is the same way you handle your own site’s GET/POST request. Just need to grab the ‘Request.Params[“SomeID”]’ or Request.Querystring(“parameter1”) in your c# code, depending what type of http request they are sending to your application. Hope this helps.

      Reply
  15. Gaurav Chhabra says

    February 8, 2013 at 10:27 AM

    Hello When i am using this code then i am getting NULL value in return when i am accessing my PHP file directly from Browser.

    and even in OUTPUT window of VS, it display just the value of a only that is “Value1” nothing else.

    my client side application is in C# using help from your code
    and my Service Side application is in PHP and the statement i am using in my PHP file is

    and one more consultation, i would like to post data that the client will enter in Textbox and i tried to put that in query but failed.

    So, it would be really appreciable if you can help me for that also along with the NULL value Return

    Reply
  16. elvloggero says

    February 8, 2013 at 3:32 PM

    Thanks for your code. It’s very useful

    Reply
  17. Carlos Rueckert says

    February 14, 2013 at 11:03 PM

    Thanks Ali, very useful

    Reply
  18. Roy says

    March 4, 2013 at 10:11 AM

    Very Useful! What a pain in the ass the default WebRequest with POST parameters…

    Thank you very much!

    Reply
  19. mandeep says

    April 8, 2013 at 12:20 AM

    Nice article. As per my research on this topic, I have seen that we can improve the security concerns regarding GET request by using HTTPS protocol.

    Reply
  20. Code says

    May 11, 2013 at 10:03 AM

    I want to get response from this url:
    https://testapi.internet.bs/Domain/Check?Domain=HASANUDDIN.INFO&ApiKey=testapi&Password=testpass”

    Note: this the original web http://www.internetbs.net/ResellerRegistrarDomainNameAPI/api/01_domain_related/01_domain_check

    but i got this error message:
    “The operation has timed out”

    Could you tell me is there something wrong from my code, here is my code:
    //create the constructor with post type and few data
    MyWebRequest myRequest = new MyWebRequest(“https://testapi.internet.bs/Domain/Check”, “POST”, “Domain=HASANUDDIN.INFO&ApiKey=testapi&Password=testpass”);
    //show the response string on the console screen.
    Console.WriteLine(myRequest.GetResponse());

    Reply
    • Md Ali Ahsan Rana says

      May 23, 2013 at 12:51 PM

      as far I can track, you need to provide “GET” instead of “POST”(as all variables in url are passed in GET method). May be the server only accepts GET requests.

      Reply
  21. Moch. Firmansyah says

    October 9, 2013 at 9:53 AM

    thx, your code is very usefull, but how to make this webrequest class asyncronously ?

    Reply
  22. Rogala says

    April 30, 2014 at 12:34 PM

    Good post to get the initial structure, but as mentioned in previous comments, this only works if a response of 200 is received, but errors out on other responses. This is not hard to add, but just don’t implement into a solution without adding necessary additional code.

    Reply
  23. Miguel says

    June 9, 2014 at 12:01 PM

    thanks you so much!..

    Reply
  24. Bryan says

    July 27, 2014 at 9:48 PM

    Hi,

    How could you use this to replace this Curl statement

    curl -H “X-Auth-User: bryanoliver” -H “X-Auth-Expires: 1406485297” -H “X-Auth-Key: 946ddd08f5fbcb3ddb0c91e3785f0630” “-H” “Accept: application/xml” “https://acb7b192c688.cloud.elementaltechnologies.com/api/jobs/1”

    Reply
  25. sudeep says

    November 19, 2014 at 4:06 AM

    {“The remote server returned an error: (500) Internal Server Error.”}

    Reply
  26. Harold Casimina says

    November 29, 2014 at 2:12 AM

    Dear Ali Ahsan,

    How can I use this in a multiple call?

    To give you the idea. I created a 2 method that calls different data.

    For instance:

    checkExisting_data() – for getting hours list
    addComboList() – for getting projects list

    But when I put this both on the Form Load, only one method is working and the other is not but when I commented the first one the second method works. So i guess there is nothing wrong with my method

    //Sample Code
    http://pastebin.com/bzWczKXc

    Please advise!
    Thank you in advance

    Reply
  27. VR says

    December 30, 2014 at 2:58 PM

    This script does not RUN.. any ideas. also i want to know how i can get the URL connect to display TRUE as in connection is TRUE .

    That way i know the code works and POST.
    THis is what i have but it does not work.

    I want to POST to URL with the STRING like:
    http://www.myurl.com/bin/usernamehere.passwordhere.morestuffhere.timeanddatehere.

    can anyone help.?

    Code:
    http://pastebin.com/Dnx7Dpam

    Reply
  28. nickjwparkNick says

    January 18, 2015 at 6:42 AM

    Great class man! really simple and got it working in a second! Thanks for your efforts!

    Reply
  29. manojitballav says

    June 7, 2015 at 7:04 PM

    what are the changes we need to do if we want to use it for a Windows Phone App

    Reply
  30. raj says

    August 7, 2015 at 12:27 AM

    i want to send an http request.. but i want that page of this http request is not show to the user….
    please solve my problem

    Reply
  31. emma OJ says

    October 26, 2015 at 5:47 PM

    I need to send a request to a payment switch with the following parameters in asp.net C# and receive an json response, any idea how

    Sample Request (JSON)
    GET
    stageserv.interswitchng.com/test_paydirect/api/v1/gettransaction.json?productid=21&transactionreference=8421941122&amount=300000 HTTP/1.1
    UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 4.0.30319.239)
    Hash: F6FF2E22F99D93DDDA52D71811FD92B3A71FA1968A66216E0D310DAD

    Sample Response (JSON)
    HTTP/1.0 200 OK
    Date: Tue, 30 Oct 2012 16:12:17 GMT
    Content-Type: application/json; charset=utf-8
    Content-Length: 333
    {“Amount”:300000,”CardNumber”:”6055″,”MerchantReference”:”8421941122″,”PaymentReference”:”ZIB|WEB|VNA|15-10-2012|015933″, “RetrievalReferenceNumber”:”000000538268″, “LeadBankCbnCode”:null, “LeadBankName”:null, “SplitAccounts[],”TransactionDate”:”2012-10-15T11:07:54.547″,”ResponseCode”:”00″,”ResponseDescription”:”Approved Successful”}

    Please help

    Reply
  32. Juan Ramos Suyón says

    December 23, 2015 at 9:45 PM

    Thank you for the information and explanation.
    Do you know how to “upload a file” using a POST request?

    Reply
  33. Ivan KL says

    January 26, 2016 at 4:27 PM

    Thanks Ali for your Work !

    Reply
  34. Lucky says

    March 15, 2016 at 5:20 AM

    can i use async for same method ??

    Reply
  35. Axil says

    December 14, 2016 at 9:42 AM

    Super simple, and complete! Sometimes it’s difficult to remember which order C# objects need to be created to get a good response. Your article was very helpful in reminding me how to properly get content into the right part of the response / request objects in C#. Thanks!

    Reply
  36. Ravi Walde says

    January 3, 2017 at 9:18 AM

    Dear Sir,
    How to use this wrapper class in my webpage .
    i have returmUrl.Aspx and .Cs page.
    please tell me the procedure for use of this wrapper class for handling HTTP get/Post request from payment gatway.
    How it will usefull for pickup response from payment gayway.
    waiting hopefully.
    thank in advance.

    Reply
  37. Susan says

    April 14, 2017 at 2:32 AM

    Hi,

    Below is my code and they are pretty simple. However, I’m encountering (500) Internal Server Error from this line.
    HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse();

    public void GetRequestID(string atoken)
    {
    string webpage_data = “INC000003785314”;
    string webpage = “https://arstest.micron.com:9443/api/arsys/v1/entry/HPD%3AIncidentInterface/?fields=values(Request ID)&q=’Incident Number’%3D”;

    ASCIIEncoding encoding = new ASCIIEncoding();
    byte[] data = encoding.GetBytes(webpage_data);
    webpage = webpage + webpage_data;
    HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(webpage);

    myRequest.Credentials = CredentialCache.DefaultCredentials;
    myRequest.Method = “GET”;
    myRequest.ContentType = “application/json”;
    myRequest.Headers.Add(“Authorization”, atoken);

    HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse();
    Stream receive_stream = response.GetResponseStream();
    StreamReader read_stream = new StreamReader(receive_stream, Encoding.UTF8);

    string str = read_stream.ReadToEnd();

    response.Close();
    read_stream.Close();
    }

    Reply
  38. Pregunton Cojonero says

    October 29, 2017 at 11:11 AM

    POST using

    1) XML

    How get response in XML
    and

    2) JSON
    How get response in JSON

    real world sampes?

    Reply
  39. Armorik says

    March 26, 2021 at 10:13 AM

    Thank you very much.

    Reply

Leave a ReplyCancel reply

Primary Sidebar

  • Facebook
  • X
  • Pinterest
  • Tumblr

Subscribe via Email

Top Picks

python local environment setup

Python Local Development Environment: Complete Setup Guide

In-Depth JWT Tutorial Guide For Beginners

JSON Web Tokens (JWT): A Complete In-Depth Beginners Tutorial

The Ultimate Git Commands CheatSheet

Git Commands Cheatsheet: The Ultimate Git Reference

web development architecture case studies

Web Development Architecture Case Studies: Lessons From Titans

static website deployment s3 cloudfront

Host Static Website With AWS S3 And CloudFront – Step By Step

Featured Dev Tools

  • JWT Decoder
  • JSON Formatter

Recently Published

automation with python

Automation With Python: A Complete Guide

python file handling

Python File Handling: A Beginner’s Complete Guide

service worker best practices

Service Worker Best Practices: Security & Debugging Guide

advanced service worker features

Advanced Service Worker Features: Push Beyond the Basics

service worker framework integration

Service Workers in React: Framework Integration Guide

Footer

Subscribe via Email

Follow Us

  • Facebook
  • X
  • Pinterest
  • Tumblr

Demos

  • Demo.CodeSamplez.com

Explore By Topics

Python | AWS | PHP | C# | Javascript

Copyright © 2025

https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_451791f6256d7d47b1ca823d03a6710e88e14be46448b0efa54090233920995c374ba3226bccd619afea3ae5b1195c2013c815b13dcf235d961ba7bb841b96ca.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_af52ba0269d003b0a37c5de7b5fcf58bfc0730dcf14c253b637a5735b5239f1c1009005caaaa9e06d799bce9192442f705c645bf419b4de00cd84dbc7b65bed0.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_c402e38f1879c18090377fb6b73b15ac158be453ecda3a54456494fe8aba42b990c293bae5424e5643d52515ffc2067e0819995be8d07d5bba9107a96780775c.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_ffc3511227531cc335353c54c3cbbaa11d0b80e5cb117478e144436c13cd05495b67af2e8950480ed54dbdabcdcef497c90fdb9814e88fe5978e1d56ce09f2cf.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_d57da9abfef16337e5bc44c4fc6488de258896ce8a4d42e1b53467f701a60ad499eb48d8ae790779e6b4b29bd016713138cd7ba352bce5724e2d3fe05d638b27.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_d286e50977f467ebee8fecdcb44e6a6b9a29f2b911dfe58b30ff4f0545aa2b19bca73246e23de9a6d2380bf20e6b8a001b5ba2051042d104c6d411b474fd3368.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_2452913ce19b095437f7615a05bcc6dcec7c412e4fd3f1d45d44556bd73c456e2ebcc5ddb4b54314dd5552860ffd20d1b95650285ffa9f4a161437a894a7fdb2.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_dccc492dbbfdac33d1411f9df909e849c7268fcf99b43007f278cde3a0adc0ae00e8cae5ec81cf255b9a6eae74e239ba1fa935572af77173219cb081f7d2327d.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_00bacf9e36181aac2b666d110cd9d82257f846766e7041b2d7b3c909b458982931ccc9b203e37098fbdfcf43ca359cf04e3824a724a6789fc204196d3a72ad29.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_b0a92cfc2eada30b83a354b8ec8977a5125e40b947055feb299f2812b4633d2e4aa334a35f6a3a016177d2dc2349ebb7d2c216b1e4ce54ed13eb633fa20b530a.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_d9cc71d48666063bc3bf07017c5ccec932b0065fe8e6ff50d8fa5a414d906c77927570af9d642b97761242bc879b9a7190543dea34ac0392f94ebbea70365460.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_bb8058a9e234a7ffaa98891b1df7f6b8e67410e6984568b151daa05113b8c7f89d7b5918ae73f020998a16f7f5a087a13d6a9a5e5d7c301e2ca12fd9d1f8d177.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_647fb67570c6108fb10ae6785a1abdbecac99ffcf80351d0bef17c3cf783dce497b1895fcdaae997dacc72c359fbfb128cc1540dd7df56deb4961e1cd4b22636.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_f7a298a0f1f754623fe3b30f6910ce2c1373f715450750bd7a391571812b00df1917e2be90df6c4efc54dbdfda8616278a574dea02ba2c7a31992768df8db334.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_df30604d5842ef29888c3c1881220dc6d3f8854666d94f0680c5f38aa643c5fb79b10eb9f10998d8856eb24ca265783195937434fd6c2bb8e4846df0277a7fb7.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_f17fe6fb0993f1703181d7ae9e9ea570f3d33a43afd6f2a4567daa1a6745698c7b8193dc72d50991d2dd87cd3dcf663959206607d193a9b57926d061a1f50aef.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_945dcbab2c2a131f3c90f4fb91776b76066d589f84fb55bff25cd5d79a56218000616bfca1f0af9a74f32348693707af49e8fe624de8aa34f1e1c5b6a25709cf.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_65820d252e1b93596de6697fd5f02483f3e2524a0696c7d698b64745edb32bf5831a90e556842f5f88c8209766cc78ca3a41cf783d20236a9f90d4a7ea7b3e72.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_7286884797a1210857e2a36f8ab46604b0034b6abf512380447a5763c873db6a72b8547f660053de0ea69faef1eb64878f39ff4b0ea86c963efab95764a3bf5b.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_cbcf6c279ac6c6a25ae138bf964e64a5fd90d22dcdf8a53b6fe7b72cefa51063bfb0181a6e50dd2acdcae2795619887d1d83b10461e44e5103be756f2588d837.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_363c21d17cca8c70cf23e95758b90358dd89a439478ca10666cfa9e6febabafe864694b2487ff852adec1a34fb2170699819c3c699af055b4d8728aa239cf51e.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_47965bc586b95810c925b9df3314e0c9a5cd121e70ca0831f87df0bc034695de4f83ecf2def86f737e14614ee138794473cf32cd3082a5d38db9dec0c1f266fa.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_12aa201cea075846d266536aa222d64d4088b851d87f55dac5e611b77add6826c8ebc6e82650fcd1a9e88a05a0072dedd195719c5f64cd4580a0acd8aee05d92.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_bc81cc95286a4f55674f2ec291d6b8b93ff434625aca56ff77115dd05290515f93dda858c8737b08c7c58485385734158257573ac71c38bd3342f1da50311701.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_6d5d3641350c17478ec5b573ea5a5a8699344e198c94d008790430950efcd1d229c26d85f6d074d05114b27ea5e2cb042e4ed9494860e1779ac254b96a683eb8.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_d87ea86dd0e7ecdd5fe7a5bb67becf943e57c3add866b456034d51663d099031bd563e12f61fdccc044969adf938a8584ed22ccd401ab8b669e20e4f92fb54e8.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_35311c3d71a3605fad4e1d6b50f3911311cdcc46418bdf56d6d0308a75a69585269ee7582a335e29989adf308fa1a81a10a2c2d4e257e9d680447a4996f6269e.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_f4fc182ef03c12e9dcadd6febc3dbaa4a29134469057ca9e8ec0be2f2de29a494514ff4b59798e74debf26f78b2df2b3e2665c69b77035761fb463b783202915.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_85c0f2769456e60153b0fd8364b82a035da53384f62de342d9bdca806f3f1ea56486919a00497a18d457949c82bf8bfacc4423fc332074ddf71a49a8fe628fff.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_1b7e49e98f5960d71636812e807832cc98a24f48bc493652ddb2f9c4ce08bc89a8fd5d9550a8e2887d1d8887ce02924a878361c296d21ceba18a56f3ace130bd.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_09eecfdd96206ed13830b4b93cfb2cc75cd38083671a34194437b5734b5bb38712209dc335b07e3266ceb3c3a44a155b9bbe5f3e0e1105b19dd45d3def76f020.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_4c089fbdb88e3b624a6f884d3ba1bf606f003bfcd3742376d0d353cd62181dc663aa3811a56361c3100de488fc4d6595a50de2b26f058921ba74f5f2c1b5be00.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_897ff6ac314c5f5e0f496c6af624bd9abf296a02cb5aeb850b9220b6dc3ce2fc4004cb02ed8b59d59d4b9c9d90f050d6eebc1d08ecaebab2f671f7d9367e6410.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_67d1e619e71d36ae00ddcf85ee18628bb4eb64fcb3d6119b463e75cb987013420a21136d19cd03e6634ccc01cfa9af4a357930e4cf6900953b7812efb4f249fb.js