Solve CORS problem

Add option handler below

if (context.Request.HttpMethod.ToLower().Equals("options")) {

context.Response.StatusCode = 200;
context.Response.KeepAlive = false;
context.Response.Headers.Add("Access-Control-Allow-Origin: *");
context.Response.Headers.Add("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
context.Response.Headers.Add("Access-Control-Allow-Methods: GET, POST, PUT");

byte[] b = Encoding.UTF8.GetBytes("SUCCESS");
context.Response.ContentLength64 = b.Length;
var output = context.Response.OutputStream;
output.Write(b, 0, b.Length);
context.Response.Close();
}

留言

這個網誌中的熱門文章

D-Link DIR-882 刷padavan老毛子教程!含刷機包及詳細步驟

實測【Targus AKB55】窮人的Magic Keyboard

4K螢幕字體會不會太小?不會!