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业务接口了…
以上就是C#调用Python的URL接口的示例的详细内容,更多关于C#调用Python的URL接口的资料请关注其它相关文章!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)