一、API接口
含义:将需要别人访问的内容写在在Controller的action中,让外部人员能通过http请求访问action中的内容,前提是api需要发布到外网!
在后台通过http请求访问别人的api接口获取信息——》写成一个类。
需要将本地的信息做好逻辑返回给别人调用时——》写成一个api接口
获取和发送一定要分清楚
二、API接口——》后台通过http接口获取数据
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serviceAddress);
request.Method = "get";
request.ContentType = "application/json";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string encoding = response.ContentEncoding;
if (encoding == null || encoding.Length < 1)
{
encoding = "UTF-8"; //默认编码
}
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(encoding));
retString = reader.ReadToEnd();//返回数据
原文:https://www.cnblogs.com/LanHai12/p/15258047.html