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();
}
留言
張貼留言