2021年8月17日 星期二

呼叫網址及驗證機制

呼叫端
using (HttpClient httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", token);
var stringContent = new StringContent(JsonConvert.SerializeObject(new {p1=123,p2="aaa"}), System.Text.Encoding.UTF8, "application/json");
using (var response = await httpClient.PostAsync(url, stringContent)) 
{ }
}

被呼叫端
[AllowAnonymous]
[HttpPost]
public void xxx(int p1,string p2)
{
if (Request.Headers["Authorization"]!=token) {
                Response.Write("非法呼叫");
                Response.StatusCode = (int)System.Net.HttpStatusCode.Unauthorized;
                return;
        }
}

沒有留言:

input 連結 datalist 用程式控制彈出選項

範例: nextTick(() => document.querySelector('input').showPicker());  ※僅支援現代瀏覽器