首页 > Windows开发 > 详细

API接口和WebService服务

时间:2021-09-13 10:11:44      阅读:29      评论:0      收藏:0      [点我收藏+]

一、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();//返回数据

 

API接口和WebService服务

原文:https://www.cnblogs.com/LanHai12/p/15258047.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!