Use of Request and Response in ASP.Net

2019-02-24 19:14发布

What is the difference between "Request" and "Response" terminologies in ASP.net? I am using ASP.net 3.5.

Suppose I have to make somebody understand about these terms. What should i say ?

标签: asp.net http
2条回答
走好不送
2楼-- · 2019-02-24 20:00

The Request is what a web client sends to the web server. The Response is what the web server sends - well, in response. Both are defined in the HTTP specification. (How they are structured, what information and meta data they include, etc.)

ASP.Net encapsulates these concepts in respective classes to make them programmatically accessible.

Edit: Specific examples as requested in the comments:

Request.QueryString

If you have a URL like the following:

http://www.host.com/Page.aspx?name=Henry&lastName=Ford

The part after the ? is the query string. (name=Henry&lastName=Ford <= The query string)

This is one common way to pass arguments to the server as part of the Request. In your server code you can access these arguments by using Request.QueryString:

string name = Request.QueryString["name"];
string lastName = Request.QueryString["lastName"];

Response.Redirect

Your server received a Request for a page and you want to redirect to another location. With the Response.Redirect() method, you add a specific piece of information to the Response that causes the browser to immediately go to this other page.

// This tells the browser to load google
Response.Redirect("http://www.google.com");
查看更多
我命由我不由天
3楼-- · 2019-02-24 20:00

There is a IIS (Internet Information Services) Server.. In ASP.Net, you can Request for data from the server, and what the server sends you is a Response

查看更多
登录 后发表回答