c# make http request
private static readonly HttpClient client = new HttpClient();
var responseString = await client.GetStringAsync("http://www.example.com/recepticle.aspx");
c# make http request
private static readonly HttpClient client = new HttpClient();
var responseString = await client.GetStringAsync("http://www.example.com/recepticle.aspx");
example HttpClient c# Post
//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;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us