asp.net实现遍历Request的信息操作示例

作者:willingtolove 时间:2022-11-15 23:15:18 

本文实例讲述了asp.net实现遍历Request的信息操作。分享给大家供大家参考,具体如下:

#需求:

在服务端获取从客户端发送过来的所有数据信息;

#方案:

1、服务端代码


public void ProcessRequest(HttpContext context)
{
 //打印所有参数信息
 context.Response.Write("Params:");
 for (int i = 0; i < context.Request.Params.Count; i++)
 {
   context.Response.Write("<li>" + context.Request.Params.Keys[i].ToString() + " = " + context.Request.Params[i].ToString());
 }
 context.Response.Write("<hr>");
 //打印form信息
 context.Response.Write("Form:");
 for (int i = 0; i < context.Request.Form.Count; i++)
 {
   context.Response.Write("<li>" + context.Request.Form.Keys[i].ToString() + " = " + context.Request.Form[i].ToString());        
 }
 context.Response.Write("<hr>");
 //打印query信息
 context.Response.Write("QueryString:");
 for (int i = 0; i < context.Request.QueryString.Count; i++)
 {
   context.Response.Write("<li>" + context.Request.QueryString.Keys[i].ToString() + " = " + context.Request.QueryString[i].ToString());      
 }
 context.Response.Write("<hr>");
 //打印cookies信息
 context.Response.Write("Cookies:");
 for (int i = 0; i < context.Request.Cookies.Count; i++)
 {
   context.Response.Write("<li>" + context.Request.Cookies.Keys[i].ToString() + " = " + context.Request.Cookies[context.Request.Cookies.Keys[i].ToString()].Value);        
 }
 context.Response.ContentType = "text/html";
}

2、使用postman模拟发送数据

1)、query_param

asp.net实现遍历Request的信息操作示例

2)、headers

asp.net实现遍历Request的信息操作示例

3)、form_param

asp.net实现遍历Request的信息操作示例

4)、cookies

asp.net实现遍历Request的信息操作示例

3、返回值

Params:

  • str = str

  • str1 = str1

  • form_1 = form_1

  • form_2 = form_2

  • ASP.NET_SessionId = 2eln4eqa2uv0hawyks50kfad

  • DisablePoint = true

  • QrcodePrefix =

  • UM = http://192.168.2.121/PsUM

  • MasterVisitor = 19

  • CanRegister = True

  • LoopTime = 10

  • CanDownload = {"1":false}

  • TotalVisitorNum = {"1":6}

  • cookie_test = test

  • ALL_HTTP = HTTP_CACHE_CONTROL:no-cache HTTP_CONNECTION:keep-alive HTTP_CONTENT_LENGTH:278 HTTP_CONTENT_TYPE:multipart/form-data; boundary=--------------------------358496475944465509800748 HTTP_ACCEPT:*/* HTTP_ACCEPT_ENCODING:gzip, deflate HTTP_COOKIE:ASP.NET_SessionId=2eln4eqa2uv0hawyks50kfad; DisablePoint=true; QrcodePrefix=; UM=http://192.168.2.121/PsUM; MasterVisitor=19; CanRegister=True; LoopTime=10; CanDownload={"1":false}; TotalVisitorNum={"1":6}; cookie_test=test HTTP_HOST:localhost:3805 HTTP_USER_AGENT:PostmanRuntime/7.3.0 HTTP_HEADER_1:header_1 HTTP_HEADER_2:header_2 HTTP_POSTMAN_TOKEN:1f778868-3222-479a-9863-d65ca4881a2b

  • ALL_RAW = Cache-Control: no-cache Connection: keep-alive Content-Length: 278 Content-Type: multipart/form-data; boundary=--------------------------358496475944465509800748 Accept: */* Accept-Encoding: gzip, deflate Cookie: ASP.NET_SessionId=2eln4eqa2uv0hawyks50kfad; DisablePoint=true; QrcodePrefix=; UM=http://192.168.2.121/PsUM; MasterVisitor=19; CanRegister=True; LoopTime=10; CanDownload={"1":false}; TotalVisitorNum={"1":6}; cookie_test=test Host: localhost:3805 User-Agent: PostmanRuntime/7.3.0 header_1: header_1 header_2: header_2 Postman-Token: 1f778868-3222-479a-9863-d65ca4881a2b

  • APPL_MD_PATH = /LM/W3SVC/34/ROOT

  • APPL_PHYSICAL_PATH = D:\vsproject\Projects\WebApplication1\WebApplication1\

  • AUTH_TYPE =

  • AUTH_USER =

  • AUTH_PASSWORD =

  • LOGON_USER =

  • REMOTE_USER =

  • CERT_COOKIE =

  • CERT_FLAGS =

  • CERT_ISSUER =

  • CERT_KEYSIZE =

  • CERT_SECRETKEYSIZE =

  • CERT_SERIALNUMBER =

  • CERT_SERVER_ISSUER =

  • CERT_SERVER_SUBJECT =

  • CERT_SUBJECT =

  • CONTENT_LENGTH = 278

  • CONTENT_TYPE = multipart/form-data; boundary=--------------------------358496475944465509800748

  • GATEWAY_INTERFACE = CGI/1.1

  • HTTPS = off

  • HTTPS_KEYSIZE =

  • HTTPS_SECRETKEYSIZE =

  • HTTPS_SERVER_ISSUER =

  • HTTPS_SERVER_SUBJECT =

  • INSTANCE_ID = 34

  • INSTANCE_META_PATH = /LM/W3SVC/34

  • LOCAL_ADDR = ::1

  • PATH_INFO = /test.ashx

  • PATH_TRANSLATED = D:\vsproject\Projects\WebApplication1\WebApplication1\test.ashx

  • QUERY_STRING = str=str&str1=str1

  • REMOTE_ADDR = ::1

  • REMOTE_HOST = ::1

  • REMOTE_PORT = 12131

  • REQUEST_METHOD = POST

  • SCRIPT_NAME = /test.ashx

  • SERVER_NAME = localhost

  • SERVER_PORT = 3805

  • SERVER_PORT_SECURE = 0

  • SERVER_PROTOCOL = HTTP/1.1

  • SERVER_SOFTWARE = Microsoft-IIS/10.0

  • URL = /test.ashx

  • HTTP_CACHE_CONTROL = no-cache

  • HTTP_CONNECTION = keep-alive

  • HTTP_CONTENT_LENGTH = 278

  • HTTP_CONTENT_TYPE = multipart/form-data; boundary=--------------------------358496475944465509800748

  • HTTP_ACCEPT = */*

  • HTTP_ACCEPT_ENCODING = gzip, deflate

  • HTTP_COOKIE = ASP.NET_SessionId=2eln4eqa2uv0hawyks50kfad; DisablePoint=true; QrcodePrefix=; UM=http://192.168.2.121/PsUM; MasterVisitor=19; CanRegister=True; LoopTime=10; CanDownload={"1":false}; TotalVisitorNum={"1":6}; cookie_test=test

  • HTTP_HOST = localhost:3805

  • HTTP_USER_AGENT = PostmanRuntime/7.3.0

  • HTTP_HEADER_1 = header_1

  • HTTP_HEADER_2 = header_2

  • HTTP_POSTMAN_TOKEN = 1f778868-3222-479a-9863-d65ca4881a2b


    Form:

  • form_1 = form_1

  • form_2 = form_2


    QueryString:

  • str = str

  • str1 = str1


    Cookies:

  • ASP.NET_SessionId = 2eln4eqa2uv0hawyks50kfad

  • DisablePoint = true

  • QrcodePrefix =

  • UM = http://192.168.2.121/PsUM

  • MasterVisitor = 19

  • CanRegister = True

  • LoopTime = 10

  • CanDownload = {"1":false}

  • TotalVisitorNum = {"1":6}

  • cookie_test = test

希望本文所述对大家asp.net程序设计有所帮助。

来源:https://www.cnblogs.com/willingtolove/p/9782485.html

标签:asp.net,遍历,Request
0
投稿

猜你喜欢

  • 一文详解如何在控制台显示MyBatis的SQL语句

    2023-01-09 06:43:38
  • 递归出现栈溢出stackoverflow的问题及解决

    2023-01-29 16:36:10
  • SpringBoot实现本地存储文件上传及提供HTTP访问服务的方法

    2022-09-14 19:09:12
  • Java 通过AQS实现数据组织

    2023-04-05 22:19:29
  • 详解JAVA高质量代码之数组与集合

    2022-03-31 16:42:07
  • java向下转型基础知识点及实例

    2022-07-01 11:48:38
  • java tostring方法重写代码示例

    2022-12-31 22:38:07
  • java定义受限制的类型参数操作

    2022-12-16 09:44:03
  • Java实现文件切割拼接的实现代码

    2022-04-15 08:10:03
  • Java Socket实现多线程通信功能示例

    2022-11-29 03:24:59
  • java WebSocket客户端断线重连的实现方法

    2023-05-26 22:45:18
  • mybatis自定义类型处理器TypehHandler示例详解

    2023-10-11 04:30:40
  • Java中list.contains()的用法及拓展

    2022-11-06 21:04:59
  • Java性能调优概述

    2023-07-06 05:42:51
  • Spring Cloud Gateway(读取、修改 Request Body)的操作

    2023-11-09 19:25:46
  • C# Winform消息通知之系统本地通知local toast notification

    2023-02-01 04:14:02
  • Android中判断网络是否连接实例详解

    2023-10-19 11:45:39
  • Day14基础不牢地动山摇-Java基础

    2023-03-21 09:04:46
  • C# 判断字符串为空的几种办法

    2023-05-21 16:06:44
  • 深入理解Java基础之try-with-resource语法糖

    2022-12-03 08:17:43
  • asp之家 软件编程 m.aspxhome.com