本文介绍了如何处理C#.NET GET / POST?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从PHP来我选择C#与工作,其一直很好到来之后是新的.NET。
我虽然对GET和POST的处理问题。

As I'm new to .NET after coming from PHP I chose C# to work with and its coming along nicely.I have a question though regarding the handling of GET and POST.

到目前为止,我已经建立了,我可以把这个aspx页面背后的CodeFile

So far I've established that I can put this in the codefile behind the aspx page:

if (Request.HttpMethod.ToString() == "POST") {

    Response.Write("You sent a post!")

}

和我可以和一个ELSE有处理GET,但究竟会怎么做。

and I could and an ELSE there to handle a GET, but how exactly would you do that?

在PHP中我会做这样的事情:

In PHP I would do something like this:

示例URL =

$foobar = $_GET['foo'];



能否某种灵魂请给我指点与这在C#处理。

Could some kind soul please give me pointers on dealing with this in C#.

感谢

推荐答案

的$ _GET .NET版本[]是:

The .Net version of $_GET[] is :

 Request.Querystring["parameter1"]

您不需要这样做,如果条件

You do not require to do this IF condition.

的$ _ POST .NET版本[]是:

The .Net version of $_POST[] is :

 Request.Form["paramName"];



不过没有必要IF条件。

Still no need the IF condition.

但在Asp.Net表单您不需要使用所有的时间请求类,因为回发到页面将直接包含表单数据到控制值。让我们假设你有一个名为TXT1文本框,当用户将提交表单可以直接通过访问TXT1获得这个文本框的值。

BUT in Asp.Net webform you do not require to use all the time Request class because the PostBack to the page will contain your form data directly into the control value. Let say you have a textbox called txt1, when the user will submit the form you can get the value of this textbox directly by accessing txt1.

这篇关于如何处理C#.NET GET / POST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 14:33