how to POST in c#

using System.Net.Http;

HttpClient client = new HttpClient();
/// POST ///

var values = new Dictionary<string, string>
{
    { "thing1", "hello" },
    { "thing2", "world" }
};

var content = new FormUrlEncodedContent(values);

var response = await client.PostAsync("http://www.example.com/recepticle.aspx", content);

var responseString = await response.Content.ReadAsStringAsync();

/// GET ///

var responseString = await client.GetStringAsync("http://www.example.com/recepticle.aspx");

3.5
4
SC1 90 points

                                    using System;
using System.Collections.Specialized;
using System.Net;

namespace API_Console_App
{
    class Program
    {
        static void Main(string[] args)
        {
            // Declare the API Endpoint URL
            string url = &quot;URL_HERE&quot;;

            // Create a New WebClient
            WebClient client = new WebClient();

            // Create a New NameValueCollection
            NameValueCollection values = new NameValueCollection();

            // Add Data to the NameValueCollection
            values.Add(&quot;data-name&quot;, &quot;content&quot;);

            // Upload the NameValueCollection Values to the URL
            client.UploadValues(url, values);
        }
    }
}

3.5 (4 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
c# asp.net post request c# post ? post request in c# make post request c# post request c# C# post request example c# net post http request post c# post requests in C# make a post request in httpClient c# request c# post http request c# post get class from post request c# send http post request in c# get from post c# How to use POST method in asp net C# c# how to make a post request C# Post Request With Response c# http request post send post c# create a post method in c# post example c# values post example c# c# call http post c# web post request c# http post c# post web request web request c# post c# get and post requests get and post method in c# make http post request and get response c# c# receive http post request post function c# c# asp.net get post and send .net post request c# web request post receive post request c# get response from post request c# http post c sharp http web request post c# http post call c# C# post call post request asp.net c# c# post request get response do post c# how to do a post request in C# how to make post request from C# post request with web request C# method.post in c# c# post request[&quot;&quot;] how to send post c# Post with c# app c# post and get response http post method in c#.net http post method in c# How to make a post request c# c# HTTP POST json c# http request post example post metod in c# C# http post request Make post request with c# http post request c# http post c# http post and get i c# http get and post c# c# post post method in c# c# post request C# request post post in c# post method c# post c# post and get c# c# http web request post example c# make post request making post requests in c# WebRequest c# post create request c# c# psot request send http request c# c# submit post request c# httpclient post http post/get opraion c# httpwebrequest post request post c# send post request C# how create post request method in C# Make a web request with HttpRequest c# send request send string http post c# http post request c# c# make http request send get request c# function C# make http post with body post request c# 4 c# send http request .net c# post request make a post request c# c# post get request how to POST in c#
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source