{"id":46,"date":"2020-06-02T20:13:29","date_gmt":"2020-06-02T20:13:29","guid":{"rendered":"http:\/\/bahadirmeric.net\/bahadir\/?p=46"},"modified":"2020-06-02T20:13:29","modified_gmt":"2020-06-02T20:13:29","slug":"post-methoduyla-sayfaya-yonlenmek","status":"publish","type":"post","link":"http:\/\/bahadirmeric.net\/bahadir\/2020\/06\/02\/post-methoduyla-sayfaya-yonlenmek\/","title":{"rendered":"POST Methoduyla sayfaya y\u00f6nlenmek"},"content":{"rendered":"\n<p>Uzunca say\u0131lacak bir aradan sonra tekrar merhaba. \u0130\u015flerin yo\u011funlu\u011fundan dolay\u0131 bir s\u00fcredir yazam\u0131yordum. Bir projede kullanmak \u00fczere \u015f\u00f6yle bir y\u00f6nteme ihtiyac\u0131m oldu.<\/p>\n\n\n\n<p>\u015eimdi d\u00fc\u015f\u00fcn\u00fcn bir web sayfan\u0131z var ve bu web sayfas\u0131ndan ba\u015fka bir web sayfas\u0131na belli de\u011fi\u015fkenlere de\u011ferler g\u00f6ndererek g\u00f6ndermi\u015f oldu\u011funuz de\u011ferlere g\u00f6re y\u00f6nlendi\u011finiz web sayfas\u0131n\u0131n sizin ekran\u0131n\u0131za y\u00fcklenmesini yani tamamen a\u00e7\u0131lmas\u0131n\u0131 istiyorsunuz. Normalde bu i\u015fte ne var dedi\u011finizi duyar gibiyim. Bunun en basit y\u00f6ntemi de asl\u0131nda GET metodunu kullan\u0131p de\u011fi\u015fken ve de\u011ferleri sayfay\u0131 \u00e7a\u011f\u0131r\u0131rken ge\u00e7menizdir. Fakat baz\u0131 siteler yada ba\u011flant\u0131 sa\u011flayaca\u011f\u0131n\u0131z yerler bu \u015fekilde verilerin a\u00e7\u0131kta gelmesini istemezler i\u015fte b\u00f6yle durumlarda POST metodunu kullanarak sayfaya ula\u015fman\u0131z ve kendi ekran\u0131n\u0131zda y\u00fcklenmesini sa\u011flaman\u0131z gerekir.<\/p>\n\n\n\n<p>Bu y\u00f6nteme en iyi \u00f6rnek olarak da benim projede geli\u015ftirdi\u011fim kodu veriyorum. Kodu vermeden \u00f6ncede iki adet sayfa haz\u0131rlaman\u0131z\u0131 bu kodu \u201cDefault.aspx\u201d ismindeki sayfan\u0131za eklemenizi \u00f6neriyorum;<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Web;\nusing System.Web.UI;\nusing System.Web.UI.WebControls;\nusing System.Collections.Specialized;\nusing System.Web.Mvc;\nusing System.Text;\n \nnamespace PostMethod_Test\n{\n    public partial class _Default : System.Web.UI.Page\n    {\n        protected void Page_Load(object sender, EventArgs e)\n        {\n            string url = &quot;ReadPost.aspx&quot;;\n            NameValueCollection data = new NameValueCollection();\n            data.Add(&quot;recordId&quot;, &quot;ASHD123198234234HDGS&quot;);\n            data.Add(&quot;phoneNumber&quot;, &quot;5326665544&quot;);\n \n            \/\/Set a name for the form\n            string formID = &quot;PostForm&quot;;\n            \/\/Build the form using the specified data to be posted.\n            StringBuilder strForm = new StringBuilder();\n            strForm.Append(&quot;&lt;form id=\\&quot;&quot; + formID + &quot;\\&quot; name=\\&quot;&quot; +\n                           formID + &quot;\\&quot; action=\\&quot;&quot; + url +\n                           &quot;\\&quot; method=\\&quot;POST\\&quot;&gt;&quot;);\n \n            foreach (string key in data)\n            {\n                strForm.Append(&quot;&lt;input type=\\&quot;hidden\\&quot; name=\\&quot;&quot; + key +\n                               &quot;\\&quot; value=\\&quot;&quot; + data&#x5B;key] + &quot;\\&quot;&gt;&quot;);\n            }\n \n            strForm.Append(&quot;&lt;\/form&gt;&quot;);\n            \/\/Build the JavaScript which will do the Posting operation.\n            StringBuilder strScript = new StringBuilder();\n            strScript.Append(&quot;&lt;script language=\\&quot;javascript\\&quot;&gt;&quot;);\n            strScript.Append(&quot;var v&quot; + formID + &quot; = document.&quot; +\n                             formID + &quot;;&quot;);\n            strScript.Append(&quot;v&quot; + formID + &quot;.submit();&quot;);\n            strScript.Append(&quot;&lt;\/script&gt;&quot;);\n            \/\/Return the form and the script concatenated.\n            \/\/(The order is important, Form then JavaScript)\n            this.Page.Controls.Add(new LiteralControl(strForm.ToString() + strScript.ToString()));\n        }\n    }\n}\n<\/pre><\/div>\n\n\n<p>Di\u011fer sayfaya ise a\u015fa\u011f\u0131daki kodu eklemenizi \u00f6neriyorum. B\u00f6ylece verinin iletilip iletilmedi\u011fini g\u00f6rm\u00fc\u015f olacaks\u0131n\u0131z.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Web;\nusing System.Web.UI;\nusing System.Web.UI.WebControls;\n \nnamespace PostMethod_Test\n{\n    public partial class ReadPost : System.Web.UI.Page\n    {\n        protected void Page_Load(object sender, EventArgs e)\n        {\n            try\n            {\n                Response.Write(Request.Form&#x5B;&quot;recordId&quot;].ToString() + &quot;&lt;br \/&gt;&quot;);\n                Response.Write(Request.Form&#x5B;&quot;phoneNumber&quot;].ToString() + &quot;&lt;br \/&gt;&quot;);\n            }\n            catch (Exception ex)\n            {\n                Response.Write(ex.Message);\n            }\n        }\n    }\n}\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>Uzunca say\u0131lacak bir aradan sonra tekrar merhaba. \u0130\u015flerin yo\u011funlu\u011fundan dolay\u0131 bir s\u00fcredir yazam\u0131yordum. Bir projede kullanmak \u00fczere \u015f\u00f6yle bir y\u00f6nteme ihtiyac\u0131m oldu. \u015eimdi d\u00fc\u015f\u00fcn\u00fcn bir web sayfan\u0131z var ve bu web sayfas\u0131ndan ba\u015fka bir web sayfas\u0131na belli de\u011fi\u015fkenlere de\u011ferler g\u00f6ndererek g\u00f6ndermi\u015f oldu\u011funuz de\u011ferlere g\u00f6re y\u00f6nlendi\u011finiz web sayfas\u0131n\u0131n sizin ekran\u0131n\u0131za y\u00fcklenmesini&#8230; <a class=\"continue-reading-link\" href=\"http:\/\/bahadirmeric.net\/bahadir\/2020\/06\/02\/post-methoduyla-sayfaya-yonlenmek\/\"> Continue reading <span class=\"meta-nav\">&rarr; <\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":16,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[7,4,6],"class_list":["post-46","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c","tag-asp-net","tag-c","tag-visual-studio"],"_links":{"self":[{"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/posts\/46","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/comments?post=46"}],"version-history":[{"count":1,"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/posts\/46\/revisions"}],"predecessor-version":[{"id":47,"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/posts\/46\/revisions\/47"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/media\/16"}],"wp:attachment":[{"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/media?parent=46"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/categories?post=46"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/tags?post=46"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}