C#调用Python的URL接口的示例
作者:有翅膀的大象 时间:2022-08-22 21:49:27
VS2013的简单WInForm控件,通过WebRequest,WebResponse来访问,接收:
private void btn_interface_Click(object sender, EventArgs e)
{
string url = "http://127.0.0.1:5000";
WebRequest wRequest = WebRequest.Create(url);
wRequest.Method = "GET";
wRequest.ContentType = "text/html;charset=UTF-8";
WebResponse wResponse = wRequest.GetResponse();
Stream stream = wResponse.GetResponseStream();
StreamReader reader = new StreamReader(stream, System.Text.Encoding.Default);
string str = reader.ReadToEnd(); //url返回的值
reader.Close();
wResponse.Close();
}
Python 简易接口:http://127.0.0.1:5000
from flask import Flask
#创建flask对象
app = Flask(__name__)
#创建路由'/'
@app.route('/')
def home():
return "Hello,World!"
#当用户请求'/'资源时,回传"Hello,World!"
#启动flask,并设定端口为5000
app.run(port = 5000)
基于这种访问方式,就可以用C#调用机器学习等人工智能及其它python业务接口了...
来源:https://www.cnblogs.com/shiningleo007/p/13534511.html
标签:c#,调用,python,url,接口
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
SQL语句练习实例之五 WMS系统中的关于LIFO或FIFO的问题分析
2011-11-03 16:59:59
Python中is和==的区别详解
2022-08-22 10:53:09
CSS背景属性5个应用实例
2009-09-13 20:54:00
python排序算法之选择排序
2023-03-15 11:56:56
![](https://img.aspxhome.com/file/2023/2/65112_0s.png)
oracle 更改数据库名的方法
2009-10-24 18:20:00
ASP下检测图片木马的函数代码
2011-02-05 10:43:00
Python操作CSV格式文件的方法大全
2023-07-08 18:57:45
![](https://img.aspxhome.com/file/2023/8/71488_0s.png)
jupyter notebook参数化运行python方式
2022-09-10 21:38:55
![](https://img.aspxhome.com/file/2023/1/70111_0s.jpg)
3个asp简单技巧
2009-11-26 20:55:00
概述javascript在Google IE中的调试技巧
2023-08-08 11:50:29
![](https://img.aspxhome.com/file/2023/8/55928_0s.jpg)
asp导出CSV格式数据
2008-12-24 21:25:00
js金额浮点格式化控件
2008-08-01 16:52:00
Django分组聚合查询实例分享
2023-08-07 21:44:16
本地计算机无法启动Apache故障处理
2023-07-17 13:06:48
Python MongoDB 插入数据时已存在则不执行,不存在则插入的解决方法
2022-11-16 20:48:41
网站导航设计的6大分类
2010-07-12 18:46:00
![](https://img.aspxhome.com/file/UploadPic/20107/12/01-25s.jpg)
Go中的应用配置管理详解
2023-06-21 00:40:55
PHP概率计算函数汇总
2023-11-19 08:06:19
Golang嵌入资源文件实现步骤详解
2023-06-21 08:52:36
js 玩转正则表达式之语法高亮
2023-06-24 05:35:42