private void getContextCallback(IAsyncResult ar)
{
HttpListener server = (HttpListener)ar.AsyncState;
HttpListenerContext ctx = server.EndGetContext(ar);
this.httpserver.BeginGetContext(new AsyncCallback(getContextCallback), this.httpserver);
ctx.Response.StatusCode = 200;
ctx.Response.ContentType = "application/json";
ctx.Response.AppendHeader("Access-Control-Allow-Origin", "*");
{
HttpListener server = (HttpListener)ar.AsyncState;
HttpListenerContext ctx = server.EndGetContext(ar);
this.httpserver.BeginGetContext(new AsyncCallback(getContextCallback), this.httpserver);
ctx.Response.StatusCode = 200;
ctx.Response.ContentType = "application/json";
ctx.Response.AppendHeader("Access-Control-Allow-Origin", "*");
string action = ctx.Request.QueryString["action"];
switch (action)
{
case "finger":
getFinger(ctx);
break;
case "idcard":
getIDCard(ctx);
break;
case "signature":
getSignature(ctx);
break;
}
}
最重要的一句就是: ctx.Response.AppendHeader("Access-Control-Allow-Origin", "*");
添加这句就好使了