Processing http post requests from outside own websitehttp://forums.asp.net/t/1791388.aspx/1?Processing+http+post+requests+from+outside+own+websiteTue, 17 Apr 2012 02:36:30 -040017913884925825http://forums.asp.net/p/1791388/4925825.aspx/1?Processing+http+post+requests+from+outside+own+websiteProcessing http post requests from outside own website <p>Hi All</p> <p>Eventual goal is to&nbsp;receive and process https post&nbsp;message from Worldpay after customer has gone through their payment process. Example worldpay have given of the&nbsp;'message' from their end is:</p> <pre class="prettyprint">POST /fail?installation=205844&amp;msgType=authResult HTTP/1.0Content-Type: application/x-www-form-urlencoded; charset=UTF-8Host: www.worldpay.comContent-Length: 973User-Agent: WJHRO/1.0 (WorldPay Java HTTP Request Object)region=new&#43;format&#43;region&amp;authAmountString=%26%23163%3B10.00&amp;_SP.charEnc=UTF-8&amp;desc=&amp;tel=&amp;address1=new&#43;format&#43;address1&amp;countryMatch=N&amp;cartId=15615166165&amp;address2=new&#43;format&#43;address2&amp;address3=new&#43;format&#43;address3&amp;town=city&amp;region=county&amp;callbackPW=&amp;lang=en&amp;rawAuthCode=A&amp;transStatus=Y&amp;amountString=%26%23163%3B10.00&amp;authCost=10.00&amp;currency=GBP&amp;installation=205844&amp;amount=10.00&amp;wafMerchMessage=waf.warning&amp;countryString=United&#43;Kingdom&amp;displayAddress=new&#43;format&#43;address1%0Anew&#43;format&#43;address2%0Anew&#43;format&#43;address3%0Anew&#43;format&#43;town%0Anew&#43;format&#43;region&amp;transTime=1313762603546&amp;name=AUTHORISED&amp;testMode=0&amp;ipAddress=192.168.90.15&amp;fax=&amp;rawAuthMessage=cardbe.msg.authorised&amp;instId=205844&amp;AVS=2004&amp;compName=BG&#43;Address&#43;change&amp;authAmount=10.00&amp;postcode=postcode&amp;cardType=Visa&amp;cost=10.00&amp;authCurrency=GBP&amp;country=GB&amp;charenc=UTF-8&amp;email=darren.irwin%40test.worldpay.com&amp;address=new&#43;format&#43;address1%0Anew&#43;format&#43;address2%0Anew&#43;format&#43;address3&amp;transId=1300002227&amp;msgType=authResult&amp;town=new&#43;format&#43;town&amp;authMode=A</pre> <p>Anyway I wanted to start with the very basics&nbsp;so I'm trying out&nbsp;a very simple&nbsp;test:</p> <p>I've put this form in the source plain&nbsp;html page:</p> <pre class="prettyprint">&lt;form id="frm_post" action="post_recv.aspx" target="_blank" method="POST" &gt; &lt;input type="text" id="txtName2&Prime; name="name2&Prime; /&gt; &lt;input type="text" id="txtAddr2&Prime; name="addr2&Prime; /&gt; &lt;input type="submit" value="Send Using Post" /&gt; &lt;/form&gt;</pre> <p><br />And this is the post_recv.aspx page:</p> <pre class="prettyprint">&lt;%@ page language="C#" %&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Post: Receiver&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;table border="2&Prime; cellpadding="7&Prime; cellspacing="2&Prime; &gt; &lt;tr&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Address&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;% Response.Write(Page.Request.Form["name2"]); %&gt;&lt;/td&gt; &lt;td&gt;&lt;% Response.Write(Page.Request.Form["addr2"]); %&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt;</pre> <p><br> When I submit the form&nbsp;on the source page it goes to post_recv.aspx but rather than display the values it just shows the source code of post_recv.aspx in browser&nbsp;(everything in the &lt;body&gt; tags)</p> <p>I'm using webmatrix2 beta and I'm doing this on my localhost. I couldn't find an example in webmatrix so I borrowed the example and&nbsp;c# code from here:</p> <p><a href="http://triaslama.wordpress.com/2008/05/01/interacting-with-get-and-post-methods-in-aspnet/">http://triaslama.wordpress.com/2008/05/01/interacting-with-get-and-post-methods-in-aspnet/</a></p> <p><br> &nbsp;</p> 2012-04-10T22:53:11-04:004925826http://forums.asp.net/p/1791388/4925826.aspx/1?Re+Processing+http+post+requests+from+outside+own+websiteRe: Processing http post requests from outside own website <p>I also made a cshtml/razor version for testing:</p> <pre class="prettyprint">&lt;!DOCTYPE html&gt; &lt;html lang=&quot;en&quot;&gt; &lt;head&gt; &lt;meta charset=&quot;utf-8&quot; /&gt; &lt;title&gt;postsend.html&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form action=&quot;postreceive.cshtml&quot; method=&quot;post&quot;&gt; &lt;input name=&quot;test1&quot; id=&quot;test1&quot; type=&quot;text&quot;&gt; &lt;input type=&quot;submit&quot;&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;</pre> <p>and postreceive.cshtml:</p> <pre class="prettyprint">@{ var nothing = "nothing"; var testvar = Request.Form["test"]; } &lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="utf-8" /&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; @nothing @testvar &lt;/body&gt; &lt;/html&gt;</pre> <p>I get the 'nothing' variable output to page but not 'testvar' which is the post</p> <p>If somebody could point me in the right direction please that would be really helpful</p> <p>Thanks<br> <br> </p> 2012-04-10T22:58:11-04:004925827http://forums.asp.net/p/1791388/4925827.aspx/1?Re+Processing+http+post+requests+from+outside+own+websiteRe: Processing http post requests from outside own website <p>Oops sorry my cshtml/razor version <strong>does&nbsp;</strong>work actually (after fixing my typo for textfield name - 'test1' instead of 'test')</p> <p>Ok so does that mean I'm ok using webpages/razor instead of c#&nbsp;to deal with post message like the one from worldpay in my first post?</p> <p>Thanks</p> 2012-04-10T23:04:00-04:004935658http://forums.asp.net/p/1791388/4935658.aspx/1?Re+Processing+http+post+requests+from+outside+own+websiteRe: Processing http post requests from outside own website <p>Hi</p> <p>I think the problem is:</p> <pre class="prettyprint"><strong>Page.Request.Form[&quot;name&quot;]</strong></pre> <p>The example use&nbsp;</p> <p><strong>Page.Request.QueryString["name"]</strong></p> <p>That's absolutely&nbsp;diffrent.</p> <p>You can use&nbsp;<strong>QueryString<strong>["name"]&nbsp;</strong></strong>get the &nbsp;value "Dino" in this url: www.yoursite.com/page1?name=dino</p> <p>but you can use Form["name"] to get that, actually, if you have a textbox id=name. You can use&nbsp;Page.Request.Form["name"].ToString();</p> <p>if it's a postback.</p> <pre class="prettyprint"> protected void Button1_Click(object sender, EventArgs e) {</pre> <pre class="prettyprint">//button click will cause a postback. string str = Page.Request.Form["Name2"].ToString(); Response.Write(str); }</pre> <p></p> <p>Hope it helpful.<br> <br> </p> <p></p> <p></p> 2012-04-17T02:36:29-04:004935659http://forums.asp.net/p/1791388/4935659.aspx/1?Re+Processing+http+post+requests+from+outside+own+websiteRe: Processing http post requests from outside own website <p>Hi</p> <p>I think the problem is:</p> <pre class="prettyprint"><strong>Page.Request.Form[&quot;name&quot;]</strong></pre> <p>The example use&nbsp;</p> <p><strong>Page.Request.QueryString["name"]</strong></p> <p>That's absolutely&nbsp;diffrent.</p> <p>You can use&nbsp;<strong>QueryString<strong>["name"]&nbsp;</strong></strong>get the &nbsp;value "Dino" in this url: www.yoursite.com/page1?name=dino</p> <p>but you can use Form["name"] to get that, actually, if you have a textbox id=name. You can use&nbsp;Page.Request.Form["name"].ToString();</p> <p>if it's a postback.</p> <pre class="prettyprint"> protected void Button1_Click(object sender, EventArgs e) {</pre> <pre class="prettyprint">//button click will cause a postback. string str = Page.Request.Form["Name2"].ToString(); Response.Write(str); }</pre> <p></p> <p>Hope it helpful.<br> <br> </p> <p></p> <p></p> 2012-04-17T02:36:30-04:00