{"id":467,"date":"2023-10-25T14:27:58","date_gmt":"2023-10-25T05:27:58","guid":{"rendered":"https:\/\/www.mobile-sta.com\/wordpress\/?p=467"},"modified":"2024-02-23T13:50:56","modified_gmt":"2024-02-23T04:50:56","slug":"web-api-%e3%82%b5%e3%83%bc%e3%83%90%e3%83%bc%e5%81%b4%e3%82%b5%e3%83%b3%e3%83%97%e3%83%abasp-net-core","status":"publish","type":"post","link":"https:\/\/www.mobile-sta.com\/wordpress\/?p=467","title":{"rendered":"Web Api \u30b5\u30fc\u30d0\u30fc\u5074\u30b5\u30f3\u30d7\u30eb(Asp.Net Core)"},"content":{"rendered":"\n\n\n<p>WEB\u30b7\u30b9\u30c6\u30e0\u3068\u306e\u9023\u643a\u3067\u306f\u3001\u3088\u304fWEB-API\u3092\u4f7f\u7528\u3057\u307e\u3059\u304c\u3001\u305d\u306eWEB-API\u306e\u30b5\u30fc\u30d0\u30fc\u5074\u51e6\u7406\u306e\u30b5\u30f3\u30d7\u30eb\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002\u52d5\u4f5c\u74b0\u5883\u3068\u3057\u3066\u306f\u3001Azure App\u30b5\u30fc\u30d3\u30b9\u3092\u4f7f\u3063\u3066\u3044\u307e\u3059\u3002(\u7121\u6599\u3067\u3044\u308d\u3044\u308d\u3067\u304d\u308b\u306e\u3067)<\/p>\n<p>\u30b5\u30f3\u30d7\u30eb\u306f\u3001\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304b\u3089\u3001post\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u9001\u4fe1\u3057\u307e\u3059\u3002\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8(url) = https:\/\/xxxxxxxx\/<span style=\"color: #000000;\">api<\/span>\/linewebhook \u3068\u3057\u3066\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002ClsPostData\u30af\u30e9\u30b9\u306f\u3001\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u53d7\u53d6\u308b\u70ba\u306e\u69cb\u9020\u4f53\u3067\u3059\u3002<\/p>\n<p>\u521d\u3081\u3066WEB-API\u3092\u898b\u308b\u4eba\u306f\u3001\u826f\u304f\u308f\u304b\u3089\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u304c\u3001<strong><span style=\"color: #0000ff;\">[HttpPost]<\/span><\/strong>\u306b\u7d9a\u304f\u95a2\u6570\u304c\u3001POST\u30ea\u30af\u30a8\u30b9\u30c8\u306e\u53d7\u4fe1\u6642\u306b\u767a\u751f\u3059\u308b\u30a4\u30d9\u30f3\u30c8\u3067\u3059\u3002<\/p>\n<p>Class\u540d = <strong><span style=\"color: #0000ff;\">LineWebHook<\/span><\/strong><span style=\"color: #000000;\">Controller<\/span> \u306e\u5834\u5408\u3001\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8(url)\u306f\u3001xxx\/<strong><span style=\"color: #ff0000;\">api<\/span><\/strong>\/<strong><span style=\"color: #0000ff;\">linewebhook<\/span><\/strong> \u3068\u306a\u308a\u307e\u3059\u3002(\u305d\u3046\u3044\u3046\u6c7a\u307e\u308a\u306b\u306a\u3063\u3066\u3044\u308b\u70ba)<\/p>\n<p>\u203b\u3010\u6ce8\u610f\u3011\u4e0b\u8a18\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u306f\u3001\u30ea\u30af\u30a8\u30b9\u30c8\u5143\u306e\u8a8d\u8a3c\u306e\u51e6\u7406\u304c\u66f8\u304b\u308c\u3066\u3044\u307e\u305b\u3093\u3002\u5b9f\u969b\u306b\u4f7f\u7528\u3059\u308b\u969b\u306b\u306f\u3001\u30ea\u30af\u30a8\u30b9\u30c8\u306e\u30d8\u30c3\u30c0\u30fc\u60c5\u5831\u306b\u30b7\u30fc\u30af\u30ec\u30c3\u30c8KEY\u3092\u30bb\u30c3\u30c8\u3057\u3066\u8a8d\u8a3c\u3059\u308b\u306a\u3069\u306e\u51e6\u7406\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">using Microsoft.AspNetCore.Mvc;\nusing System.Net.Mail; \nnamespace WebApiPost01.Controllers \n{\n\t[Route(\"api\/[controller]\")] \n\t[ApiController] \n\tpublic class LineWebHookController : ControllerBase \n\t{ \n\t\t[HttpPost] \n\t\tpublic IActionResult Post([FromBody] ClsPostData postData) \n\t\t{ \n\t\t\t\/\/ POST\u30ea\u30af\u30a8\u30b9\u30c8\u30c7\u30fc\u30bf\u6709\u7121\u30c1\u30a7\u30c3\u30af \n\t\t\tif (postData == null) \n\t\t\t{ \n\t\t\t\treturn BadRequest(\"Invalid request data.\");\n\t\t\t} \n\t\t\t\/\/ \u30e1\u30fc\u30eb\u9001\u4fe1 (POST\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u53d7\u4fe1\u3057\u305f\u6642\u306b\u5b9f\u884c\u3059\u308b\u51e6\u7406)\t\t\t\n\t\t\tFn_SendMail(postData.Title, postData.Message); \n\t\t\t\/\/ \u623b\u308a\u5024(\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074\u306b\u8fd4\u3059\u5024) \n\t\t\treturn Ok(new { Message =\n\t\t\t\t\t$\"\u53d7\u4fe1: \u30bf\u30a4\u30c8\u30eb = {postData.Title},\" + \n\t\t\t\t\t$\"\u5185\u5bb9 = {postData.Message}\"\n\t\t\t}); \n\t\t} \n\t} \/\/ EOF POST\n\n\t\/\/ POST\u30ea\u30af\u30a8\u30b9\u30c8\u53d6\u5f97\u7528\u30af\u30e9\u30b9 \n\tpublic class ClsPostData \n\t{ \n\t\tpublic string Title { get; set; } \n\t\tpublic string Message { get; set; } \n\t\t\/\/ ... \u4ed6\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u3082\u8ffd\u52a0\u3067\u304d\u307e\u3059 \n\t} \n}<\/pre>\n\n\n\n<p>Asp.Net Core\u306b\u306f\u3001\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304b\u3089\u306ePOST\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u30c6\u30b9\u30c8\u3059\u308b\u3001swagger\u3068\u3044\u3046\u30c4\u30fc\u30eb\u304c\u6a19\u6e96\u3067\u3064\u3044\u3066\u3044\u307e\u3059\u304c\u3001\u3042\u3048\u3066POSTMAN\u3067\u30c6\u30b9\u30c8\u3057\u307e\u3057\u305f\u3002<br>\u9001\u4fe1\u30c7\u30fc\u30bf\u306f\u3001\u901a\u5e38JSON\u5f62\u5f0f\u3067\u6e21\u3059\u6c7a\u307e\u308a\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002\u3053\u306eJSON\u30c7\u30fc\u30bf\u3092\u30b5\u30fc\u30d0\u30fc\u5074\u306eClsPostData\u30af\u30e9\u30b9\u3067\u53d7\u3051\u53d6\u308a\u307e\u3059\u3002<\/p>\n\n\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.mobile-sta.com\/wordpress\/wp-content\/uploads\/2023\/10\/postman-2.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"647\" src=\"https:\/\/www.mobile-sta.com\/wordpress\/wp-content\/uploads\/2023\/10\/postman-2-1024x647.jpg\" alt=\"\" class=\"wp-image-508\" srcset=\"https:\/\/www.mobile-sta.com\/wordpress\/wp-content\/uploads\/2023\/10\/postman-2-1024x647.jpg 1024w, https:\/\/www.mobile-sta.com\/wordpress\/wp-content\/uploads\/2023\/10\/postman-2-300x190.jpg 300w, https:\/\/www.mobile-sta.com\/wordpress\/wp-content\/uploads\/2023\/10\/postman-2-768x485.jpg 768w, https:\/\/www.mobile-sta.com\/wordpress\/wp-content\/uploads\/2023\/10\/postman-2.jpg 1168w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<center><a href=\"https:\/\/px.a8.net\/svt\/ejp?a8mat=3TLC2K+69NB1U+3HKU+1NLHNL\" rel=\"nofollow\">\n<img loading=\"lazy\" decoding=\"async\" border=\"0\" width=\"234\" height=\"60\" alt=\"\" src=\"https:\/\/www28.a8.net\/svt\/bgt?aid=231102812379&#038;wid=001&#038;eno=01&#038;mid=s00000016275010010000&#038;mc=1\"><\/a>\n<img loading=\"lazy\" decoding=\"async\" border=\"0\" width=\"1\" height=\"1\" src=\"https:\/\/www10.a8.net\/0.gif?a8mat=3TLC2K+69NB1U+3HKU+1NLHNL\" alt=\"\">\n<\/center>\n","protected":false},"excerpt":{"rendered":"<p>WEB\u30b7\u30b9\u30c6\u30e0\u3068\u306e\u9023\u643a\u3067\u306f\u3001\u3088\u304fWEB-API\u3092\u4f7f\u7528\u3057\u307e\u3059\u304c\u3001\u305d\u306eWEB-API\u306e\u30b5\u30fc\u30d0\u30fc\u5074\u51e6\u7406\u306e\u30b5\u30f3\u30d7\u30eb\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002\u52d5\u4f5c\u74b0\u5883\u3068\u3057\u3066\u306f\u3001Azure App\u30b5\u30fc\u30d3\u30b9\u3092\u4f7f\u3063\u3066\u3044\u307e\u3059\u3002(\u7121\u6599\u3067\u3044\u308d\u3044\u308d\u3067\u304d\u308b\u306e\u3067) \u30b5\u30f3\u30d7 &hellip; <a href=\"https:\/\/www.mobile-sta.com\/wordpress\/?p=467\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">Web Api \u30b5\u30fc\u30d0\u30fc\u5074\u30b5\u30f3\u30d7\u30eb(Asp.Net Core)<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-467","post","type-post","status-publish","format-standard","hentry","category-1"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.mobile-sta.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/467","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mobile-sta.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mobile-sta.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mobile-sta.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mobile-sta.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=467"}],"version-history":[{"count":18,"href":"https:\/\/www.mobile-sta.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/467\/revisions"}],"predecessor-version":[{"id":622,"href":"https:\/\/www.mobile-sta.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/467\/revisions\/622"}],"wp:attachment":[{"href":"https:\/\/www.mobile-sta.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mobile-sta.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mobile-sta.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}