powershell curl传送中文参数方法py接口接收(普通方式和json方式)

一、curl 传参方式

  • BAT 普通传参方式(非中文)
curl 127.0.0.1:5000/login -X POST -d  "dd=efwdfdfef&ee=3434&dfefe=3333333"
  • powershell普通方式
$body = '{"users":["yang.sun"],"msg":"' +  "中文字符串"  +'"}'
$params =[System.Text.Encoding]::UTF8.GetBytes($body)
curl 127.0.0.1:5000/login -Method POST -Body  $params
  • powershell  json方式
$body = '{"users":["yang.sun"],"msg":"' +  "中文字符串"  +'"}'
[array]$params =[System.Text.Encoding]::UTF8.GetBytes($body)
curl 127.0.0.1:5000/login -Method Post  -ContentType  "application/json" -Body $params 

二、python flask 接口接收方式

from flask import Flask
from flask import request
import json

app = Flask(__name__)

@app.route('/')
def hello_world():
   return  "Hello Word"


@app.route('/login',methods = ['POST', 'GET'])
def login():
   if request.method == 'POST':
      a = request.get_data()
      dict1 = json.loads(a)
      print(dict1)
      return json.dumps(dict1["msg"])
   else:
      return '

只接受post请求!

' if __name__ == '__main__': app.run(debug=True)

 

你可能感兴趣的:(python,windows)