呼叫端
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;
}
}
沒有留言:
張貼留言