欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#調(diào)用Python的URL接口的示例

 更新時間:2020年10月03日 10:52:08   作者:有翅膀的大象  
這篇文章主要介紹了C#調(diào)用Python的URL接口的示例,幫助大家更好的理解和學(xué)習(xí)c#,感興趣的朋友可以了解下

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

#創(chuàng)建flask對象
app = Flask(__name__)

#創(chuàng)建路由'/'
@app.route('/')
def home():
  return "Hello,World!"
#當(dāng)用戶請求'/'資源時,回傳"Hello,World!"

#啟動flask,并設(shè)定端口為5000
app.run(port = 5000)

基于這種訪問方式,就可以用C#調(diào)用機器學(xué)習(xí)等人工智能及其它python業(yè)務(wù)接口了...

以上就是C#調(diào)用Python的URL接口的示例的詳細(xì)內(nèi)容,更多關(guān)于C#調(diào)用Python的URL接口的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論