example HttpClient c# Post
C#
async Task<string> GetResponseString(string text)
{
var httpClient = new HttpClient();
var parameters = new Dictionary<string, string>();
parameters["text"] = text;
var response = await httpClient.PostAsync(BaseUri, new FormUrlEncodedContent(parameters));
var contents = await response.Content.ReadAsStringAsync();
return contents;
}
var finalResult = await GetResponseString(text);//Base code from: http://zetcode.com/csharp/httpclient/
public async string Example()
{
//The data that needs to be sent. Any object works.
var pocoObject = new
{
Name = "John Doe",
Occupation = "gardener"
};
//Converting the object to a json string. NOTE: Make sure the object doesn't contain circular references.
string json = JsonConvert.SerializeObject(pocoObject);
//Needed to setup the body of the request
StringContent data = new StringContent(json, Encoding.UTF8, "application/json");
//The url to post to.
var url = "https://httpbin.org/post";
var client = new HttpClient();
//Pass in the full URL and the json string content
var response = await client.PostAsync(url, data);
//It would be better to make sure this request actually made it through
string result = await response.Content.ReadAsStringAsync();
//close out the client
client.Dispose();
return result;
}
Also in C#:
- Title
- vb.net yes no cancel
- Category
- C#
- Title
- uwp file open picker
- Category
- C#
- Title
- how to change player cursor c# script unity
- Category
- C#
- Title
- winforms messagebox with button
- Category
- C#
- Title
- computer
- Category
- C#
- Title
- asign only common fields in c# object
- Category
- C#
- Title
- to list c#
- Category
- C#
- Title
- c# inline initialize dictionary
- Category
- C#
- Title
- how to start an if statement in c#
- Category
- C#
- Title
- unknown discriminator value mongodb
- Category
- C#
- Title
- array copy c#
- Category
- C#
- Title
- add row count devepxress report
- Category
- C#
- Title
- create dropdown in datatable c# dynamically
- Category
- C#
- Title
- c# EncoderParameter
- Category
- C#
- Title
- how to print statement in c#
- Category
- C#
- Title
- find gameobject with tag
- Category
- C#
- Title
- c# list string return concatenate
- Category
- C#
- Title
- how to pass object as test case in nunit c#
- Category
- C#
- Title
- how to see if they are aholding down a key unity
- Category
- C#
- Title
- how do i limit the amount of prefabs in unity using c# script
- Category
- C#
- Title
- C# previous method
- Category
- C#
- Title
- how to make a datatable in c#
- Category
- C#
- Title
- print gridcontrol devexpress
- Category
- C#
- Title
- razor preview
- Category
- C#
- Title
- same click event diffrenet buttonms c#
- Category
- C#
- Title
- c# multiline comment
- Category
- C#
- Title
- binding c#
- Category
- C#
- Title
- reverse a string in c#
- Category
- C#
- Title
- Read csv file into wpf C#
- Category
- C#
- Title
- query associative table ef6
- Category
- C#
- Title
- choose random gameobject from a gameobject list
- Category
- C#
- Title
- get number of sundays in a month c#
- Category
- C#
- Title
- unity up arrow input
- Category
- C#
- Title
- get query string parameter from string value c#
- Category
- C#
- Title
- unity how to set an objects postion x,y,z
- Category
- C#
- Title
- create object in c#
- Category
- C#
- Title
- Unity if object doens't exist
- Category
- C#
- Title
- and unity
- Category
- C#
- Title
- unity detect number key
- Category
- C#
- Title
- unity c# foreach
- Category
- C#
- Title
- c# create new thread
- Category
- C#
- Title
- how to get component in unity c#
- Category
- C#
- Title
- C# events
- Category
- C#
- Title
- c# print
- Category
- C#
- Title
- remove items from list c# condition
- Category
- C#
- Title
- decalre an int list mvc
- Category
- C#
- Title
- variables
- Category
- C#
- Title
- how to make % posibility to spawn an object C# in unity
- Category
- C#
- Title
- c# retrieve files in folder
- Category
- C#
- Title
- c# list remove item based on property duplicate
- Category
- C#
- Title
- how to add to a list c#
- Category
- C#
- Title
- how to find the area of a circle
- Category
- C#
- Title
- C# webclient submit form
- Category
- C#
- Title
- unity check when clicked on object
- Category
- C#
- Title
- gfortran: declare an array
- Category
- C#
- Title
- datatable return column names
- Category
- C#
- Title
- c# convert column name to number
- Category
- C#
- Title
- populate combobox from array c#
- Category
- C#
- Title
- c# how to exit program
- Category
- C#
- Title
- c# exit program
- Category
- C#
- Title
- invalidoperationexception c# ui thread
- Category
- C#
- Title
- leantween move ui
- Category
- C#
- Title
- how to mock abstract httpcontext using moq .net core
- Category
- C#
- Title
- radians to degree c#
- Category
- C#
- Title
- Request.Form
- Category
- C#
- Title
- asp.net c# set session timeout
- Category
- C#
- Title
- unity3d raycast
- Category
- C#
- Title
- perlin noise unity
- Category
- C#
- Title
- convert array to list Unity C#
- Category
- C#
- Title
- foreach syntax c#
- Category
- C#
- Title
- c# clone stream
- Category
- C#
- Title
- set label position winforms
- Category
- C#
- Title
- unity onclick addlistener
- Category
- C#
- Title
- how to reload app.config file at runtime in c#
- Category
- C#
- Title
- run async methods within a sync process
- Category
- C#
- Title
- ping with c#
- Category
- C#
- Title
- c# float to string
- Category
- C#
- Title
- combine two arraylist c#
- Category
- C#
- Title
- unity how to end a game with esc
- Category
- C#
- Title
- c# window instantly close
- Category
- C#
- Title
- how to populate listbox using list<t> c#
- Category
- C#
- Title
- c# format number with leading zeros
- Category
- C#
- Title
- c# replace foreach with lambda
- Category
- C#
- Title
- vector between two points unity
- Category
- C#
- Title
- count the number of notes in a given amount c#
- Category
- C#
- Title
- how to clear console through script unity
- Category
- C#
- Title
- c# array isn't working
- Category
- C#
- Title
- increase variable C#
- Category
- C#
- Title
- waitforseconds unity
- Category
- C#
- Title
- delegate function c#
- Category
- C#
- Title
- new TextractDocument(results)
- Category
- C#
- Title
- while loop c#
- Category
- C#
- Title
- c# get foreground window
- Category
- C#
- Title
- comment envoyer un socket C#
- Category
- C#
- Title
- toggle unity c#
- Category
- C#
- Title
- c# string to memorystream
- Category
- C#
- Title
- roulette algorithm genetic algorithm
- Category
- C#
- Title
- return random from enum
- Category
- C#
- Title
- eager loading vs lazy loading c#
- Category
- C#
- Title
- c sharp string interpolation
- Category
- C#