zoukankan      html  css  js  c++  java
  • C#调用Python的URL接口

        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();
            }
    View Code

    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)
    View Code

    基于这种访问方式,就可以用C#调用机器学习等人工智能及其它python业务接口了...

  • 相关阅读:
    P2813 母舰
    P5367 【模板】康托展开
    P1816 忠诚
    P3865 【模板】ST表
    P1913 L国的战斗之伞兵
    P4939 Agent2
    P1894 [USACO4.2]完美的牛栏The Perfect Stall
    P5017 摆渡车
    P1330 封锁阳光大学
    P5018 对称二叉树
  • 原文地址:https://www.cnblogs.com/shiningleo007/p/13534511.html
Copyright © 2011-2022 走看看