Skip to content

Instantly share code, notes, and snippets.

@VatthanachaiW
Created November 1, 2018 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VatthanachaiW/c9ba20609a39708bc89cc5598a904b05 to your computer and use it in GitHub Desktop.
Save VatthanachaiW/c9ba20609a39708bc89cc5598a904b05 to your computer and use it in GitHub Desktop.
Notification Controller for recieved data from gitlab
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Mime;
using System.Text;
using System.Web.Http;
using Notifications.Models;
using log4net;
namespace Notifications.Controllers
{
public class NotificationController : ApiController
{
private readonly ILog _logger =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// POST api/values
public void Post(PushEvent push)
{
if (ModelState.IsValid)
{
string token = "<Line Notify Token Here>";
string lineuri = "https://notify-api.line.me/api/notify";
string contentType = "application/x-www-form-urlencoded";
try
{
var requset = WebRequest.Create(lineuri);
var postdata = $"message={push}";
var data = Encoding.UTF8.GetBytes(postdata);
requset.Method = WebRequestMethods.Http.Post;
requset.ContentType = contentType;
requset.ContentLength = data.Length;
requset.Headers.Add("Authorization", $"Bearer {token}");
using (var stream = requset.GetRequestStream())
{
stream.Write(data, 0, data.Length);
var response = requset.GetResponse();
var strResponse = new StreamReader(response.GetResponseStream()).ReadToEnd();
}
}
catch (Exception exception)
{
_logger.Error(exception);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment