下面是测试环境:
CPU:E3-1230 v2
内存:16G
电脑有点不给力
操作系统:Centos7.0(虚拟机单核2G内存)
asp.net core rc2
golang v1.7beta1
下面是各自的代码:
package main import ( "fmt" "net/http" ) func main() { fmt.Println("This is webserver base!") //第一个参数为客户端发起http请求时的接口名,第二个参数是一个func,负责处理这个请求。 http.HandleFunc("/login", loginTask) //服务器要监听的主机地址和端口号 err := http.ListenAndServe("192.168.199.236:8081", nil) if err != nil { fmt.Println("ListenAndServe error: ", err.Error()) } } func loginTask(w http.ResponseWriter, req *http.Request) { //获取客户端通过GET/POST方式传递的参数 req.ParseForm() fmt.Fprint(w, "Hello World!") } |
C#
public class MyHandlerMiddleware { // Must have constructor with this signature, otherwise exception at run time public MyHandlerMiddleware(RequestDelegate next) { // This is an HTTP Handler, so no need to store next } public async Task Invoke(HttpContext context) { await context.Response.WriteAsync("Hello World!"); } // ... } public class Startup { public void ConfigureServices(IServiceCollection services) { } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app) { app.MapWhen(context => { return context.Request.Path.ToString().EndsWith("jjj.go"); }, ap => { ap.UseMiddleware<MyHandlerMiddleware>(); }); } } |