Answers for "c# post get request"

C#
2

c# post get request

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");
Posted by: Guest on January-31-2021
1

how to POST in c#

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 = "URL_HERE";

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

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

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

            // Upload the NameValueCollection Values to the URL
            client.UploadValues(url, values);
        }
    }
}
Posted by: Guest on January-31-2021

Code answers related to "c# post get request"

C# Answers by Framework

Browse Popular Code Answers by Language