Advertisement
Guest User

issue

a guest
Oct 14th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. js
  2. --------------------------------------------------------
  3. var MailBody = document.querySelector('#Mail').innerHTML;
  4. var MailBody = btoa(MailBody);
  5.  
  6. var xhttp = new XMLHttpRequest();
  7. xhttp.open("POST", "http://localhost:50975/api/maildata",true);
  8. xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
  9. var input = JSON.stringify({
  10. "MailMessage": MailBody
  11. });
  12. xhttp.send(input);
  13.  
  14. --------------------------------------------------------
  15.  
  16. asp.net controller
  17. --------------------------------------------------------
  18. using Microsoft.AspNetCore.Mvc;
  19. using System;
  20. using System.Collections.Generic;
  21. using System.Linq;
  22. using System.Threading.Tasks;
  23. using MailAPI.Models;
  24. using Newtonsoft.Json;
  25.  
  26. namespace MailAPI.Controllers
  27. {
  28. public class Test : Controller
  29. {
  30. [HttpPost("api/maildata")]
  31. public string SendMail([FromBody]List<MailBody> Mail)
  32. {
  33. var json = JsonConvert.SerializeObject(Mail);
  34. Console.Write("succes");
  35. return json;
  36. }
  37. }
  38. }
  39. --------------------------------------------------------
  40.  
  41. asp.net Model
  42. --------------------------------------------------------
  43. using System.Collections.Generic;
  44. using System.Linq;
  45. using System.Threading.Tasks;
  46.  
  47. namespace MailAPI.Models
  48. {
  49. public class MailClass
  50. {
  51. public string to { get; set; }
  52. public string subject { get; set; }
  53. public string body { get; set; }
  54.  
  55. }
  56.  
  57. public class MailBody
  58. {
  59. public string MailMessage { get; set; }
  60. }
  61. }
  62.  
  63. --------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement