Snippets

Mihamina Rakotomandimby gnrLL7: Untitled snippet

Created by Mihamina Rakotomandimby
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Text.Json;

namespace NewCustMiddleWare
{
    public class ArticleService
    {

        public List<Article> Articles { get; set; }
        private HttpClient client;

        public ArticleService()
        {
            client = new HttpClient();
            
        }

        public HttpResponseMessage PushOne(Article data)
        {
            // https://stackoverflow.com/questions/35907642/custom-header-to-httpclient-request
            // https://stackoverflow.com/questions/10679214/how-do-you-set-the-content-type-header-for-an-httpclient-request

            string url = "https://enqj9wnvk2ey.x.pipedream.net";
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, url);
            request.Content = new StringContent(JsonSerializer.Serialize<Article>(data),
                                                Encoding.UTF8,
                                                "application/json");
            HttpResponseMessage resp = client.SendAsync(request).Result;
            return resp;
        }
    }
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.