你的意思是这样的?
Get["/test"] = _ =>
{
var responseThing = new
{
this.Request.Headers,
this.Request.Query,
this.Request.Form,
this.Request.Session,
this.Request.Method,
this.Request.Url,
this.Request.Path
};
return Response.AsJson(responseThing);
};
这会给你一个像这样的输出:
{
"Form":{
},
"Headers":[
{
"Key":"Cache-Control",
"Value":[
"max-age=0"
]
},
{
"Key":"Connection",
"Value":[
"keep-alive"
]
},
{
"Key":"Accept",
"Value":[
"text/html;q=1",
"application/xhtml+xml;q=1",
"application/xml;q=0.9",
"*/*;q=0.8"
]
},
{
"Key":"Accept-Encoding",
"Value":[
"gzip,deflate,sdch"
]
},
{
"Key":"Accept-Language",
"Value":[
"en-US,en;q=0.8"
]
},
{
"Key":"Host",
"Value":[
"localhost:2234"
]
},
{
"Key":"User-Agent",
"Value":[
"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.29 Safari/537.36"
]
}
],
"Method":"GET",
"Path":"/test",
"Query":{
"23423":"fweew"
},
"Session":[
],
"Url":{
"BasePath":null,
"Fragment":"",
"HostName":"localhost:2234",
"IsSecure":false,
"Path":"/test",
"Port":null,
"Query":"23423=fweew",
"Scheme":"http",
"SiteBase":"http://localhost:2234"
}
}
您还可以在此处的 wiki 中获取 Owin 环境变量
https://github.com/NancyFx/Nancy/wiki/Hosting-nancy-with-owin#accessing-owin-environment-variables