Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- js
- --------------------------------------------------------
- var MailBody = document.querySelector('#Mail').innerHTML;
- var MailBody = btoa(MailBody);
- var xhttp = new XMLHttpRequest();
- xhttp.open("POST", "http://localhost:50975/api/maildata",true);
- xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
- var input = JSON.stringify({
- "MailMessage": MailBody
- });
- xhttp.send(input);
- --------------------------------------------------------
- asp.net controller
- --------------------------------------------------------
- using Microsoft.AspNetCore.Mvc;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using MailAPI.Models;
- using Newtonsoft.Json;
- namespace MailAPI.Controllers
- {
- public class Test : Controller
- {
- [HttpPost("api/maildata")]
- public string SendMail([FromBody]List<MailBody> Mail)
- {
- var json = JsonConvert.SerializeObject(Mail);
- Console.Write("succes");
- return json;
- }
- }
- }
- --------------------------------------------------------
- asp.net Model
- --------------------------------------------------------
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- namespace MailAPI.Models
- {
- public class MailClass
- {
- public string to { get; set; }
- public string subject { get; set; }
- public string body { get; set; }
- }
- public class MailBody
- {
- public string MailMessage { get; set; }
- }
- }
- --------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement