c# make request to rest api
C#
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
namespace ConsoleProgram
{
public class DataObject
{
public string Name { get; set; }
}
public class Class1
{
private const string URL = "https://sub.domain.com/objects.json";
private string urlParameters = "?api_key=123";
static void Main(string[] args)
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(URL);
// Add an Accept header for JSON format.
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
// List data response.
HttpResponseMessage response = client.GetAsync(urlParameters).Result; // Blocking call! Program will wait here until a response is received or a timeout occurs.
if (response.IsSuccessStatusCode)
{
// Parse the response body.
var dataObjects = response.Content.ReadAsAsync<IEnumerable<DataObject>>().Result; //Make sure to add a reference to System.Net.Http.Formatting.dll
foreach (var d in dataObjects)
{
Console.WriteLine("{0}", d.Name);
}
}
else
{
Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
}
//Make any other calls using HttpClient here.
//Dispose once all HttpClient calls are complete. This is not necessary if the containing object will be disposed of; for example in this case the HttpClient instance will be disposed automatically when the application terminates so the following call is superfluous.
client.Dispose();
}
}
}
Also in C#:
- Title
- center an image horizontally and vertically
- Category
- C#
- Title
- trello
- Category
- C#
- Title
- json stringify c#
- Category
- C#
- Title
- Move player on planets in unity 2d
- Category
- C#
- Title
- how consider the first caracter in Split c#
- Category
- C#
- Title
- unity clamp rotation
- Category
- C#
- Title
- unity serializefield
- Category
- C#
- Title
- array copy c#
- Category
- C#
- Title
- non null array length
- Category
- C#
- Title
- how to record number of times using application in c#
- Category
- C#
- Title
- c# input integer
- Category
- C#
- Title
- unity 2d joystick controls
- Category
- C#
- Title
- c# webrequest cookies
- Category
- C#
- Title
- socket in c#
- Category
- C#
- Title
- functions unity
- Category
- C#
- Title
- animations for pause menu
- Category
- C#
- Title
- how to convert float to int c#
- Category
- C#
- Title
- unity transformer double en float
- Category
- C#
- Title
- office open xml check if row is empty
- Category
- C#
- Title
- bubble sort c#
- Category
- C#
- Title
- unity timer
- Category
- C#
- Title
- c# switch statement
- Category
- C#
- Title
- why is c# say ; expected
- Category
- C#
- Title
- unity next scene
- Category
- C#
- Title
- mvc input type file
- Category
- C#
- Title
- C# Cast double to float
- Category
- C#
- Title
- f string C#
- Category
- C#
- Title
- c# convert to nullable datetime
- Category
- C#
- Title
- loop through string array c#
- Category
- C#
- Title
- if statement conditions c#
- Category
- C#
- Title
- c# directories loop
- Category
- C#
- Title
- usermanager change password without current password
- Category
- C#
- Title
- c# md5 int
- Category
- C#
- Title
- find month number from date C#
- Category
- C#
- Title
- file picker uwp c#
- Category
- C#
- Title
- how to remove vowels from a sttring using regex c#
- Category
- C#
- Title
- How can you learn C# on your own
- Category
- C#
- Title
- while loop check condition c#
- Category
- C#
- Title
- c# zip a file
- Category
- C#
- Title
- loop gridcontrol devexpress c#
- Category
- C#
- Title
- ignore fakeiteasy
- Category
- C#
- Title
- internal c#
- Category
- C#
- Title
- sum the digits in c#
- Category
- C#
- Title
- c# generic abstract method
- Category
- C#
- Title
- modificare una strinfa in c#
- Category
- C#
- Title
- unity object array
- Category
- C#
- Title
- Instantiate c#
- Category
- C#
- Title
- datetitime contrusctor c#
- Category
- C#
- Title
- move character unity
- Category
- C#
- Title
- C# previous method
- Category
- C#
- Title
- c list add element
- Category
- C#
- Title
- C# invoke
- Category
- C#
- Title
- .net core get image from url
- Category
- C#
- Title
- how to generate random unique id in c#
- Category
- C#
- Title
- wpf get name of clicked element
- Category
- C#
- Title
- unity instantiate an object
- Category
- C#
- Title
- C# enum
- Category
- C#
- Title
- how to see if they are aholding down a key unity
- Category
- C#
- Title
- unity rotate object c#
- Category
- C#
- Title
- C# Unknown column 'FundAllocation' in 'field list
- Category
- C#
- Title
- c sharp create dictionary
- Category
- C#
- Title
- try catch c#
- Category
- C#
- Title
- c# clear list items
- Category
- C#
- Title
- c# remove spaces from string
- Category
- C#
- Title
- unity rigidbody constraints
- Category
- C#
- Title
- c# wait for seconds
- Category
- C#
- Title
- how to join array indexes with comma in c#
- Category
- C#
- Title
- drag object unity 2d
- Category
- C#
- Title
- get waht is differnt between two arrays c#
- Category
- C#
- Title
- c# get full URL of page
- Category
- C#
- Title
- c# ^ operator
- Category
- C#
- Title
- c# ramdom
- Category
- C#
- Title
- unity material offset script
- Category
- C#
- Title
- enums as numbers c#
- Category
- C#
- Title
- unitt only 1 number float
- Category
- C#
- Title
- value is null to insert in c#
- Category
- C#
- Title
- how to flip selection in aseprite
- Category
- C#
- Title
- unity how to end a game with esc
- Category
- C#
- Title
- mailkit send attachment
- Category
- C#
- Title
- C# sprint key
- Category
- C#
- Title
- max of array C#
- Category
- C#
- Title
- how to get joypad axis input unity
- Category
- C#
- Title
- c# windows application get current path
- Category
- C#
- Title
- c# new dictionary linq
- Category
- C#
- Title
- create char array c#
- Category
- C#
- Title
- remove items from list c# condition
- Category
- C#
- Title
- how to raycast unit
- Category
- C#
- Title
- unity how to see what scen you are in
- Category
- C#
- Title
- c# find duplicates in list of strings
- Category
- C#
- Title
- c# making a folder wpf
- Category
- C#
- Title
- c# console writeline color
- Category
- C#
- Title
- c# discord bot
- Category
- C#
- Title
- unity lerp
- Category
- C#
- Title
- get permission to write read file and directory on file system C#
- Category
- C#
- Title
- how does Pow work C#
- Category
- C#
- Title
- how to pass object as test case in nunit c#
- Category
- C#
- Title
- accessing form controls from another class c#
- Category
- C#
- Title
- check connection c#
- Category
- C#
- Title
- c# clone stream
- Category
- C#
- Title
- c sharp list indexer
- Category
- C#