Python接口自動化(二)接口開發

djangohtml

    • 配置開發環境
      • 相關命令
        • python manage.py runserver 127.0.0.1:8000
          在指定的地址和端口啓動服務
        • python manage.py startapp api
          生成django項目應用目錄
    • 開發接口流程
      • 在項目名文件夾下的urls.py添加映射的端口名和路徑
      • 到views.py添加須要映射的方法
      • 啓動項目後,前臺展現結果
    • post請求開發
      • 先在templates下建立一個html新文件
      • 接着根據前端請求端口名login和請求方式POST進行判斷
      • 打開頁面後
        • 請求

          curl 'http://127.0.0.1:8000/login/' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' -H 'Origin: http://127.0.0.1:8000' -H 'Upgrade-Insecure-Requests: 1' -H 'Content-Type: application/x-www-form-urlencoded' -H 'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3' -H 'Referer: http://127.0.0.1:8000/login/' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: zh-CN,zh;q=0.9' --data 'username=23124412&password=231321' --compressed
        • 返回
    • get
      • 根據前端login端口在地址欄中請求的參數判斷
      • 打開頁面請求後

        curl 'http://127.0.0.1:8000/login/?username=1111' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: zh-CN,zh;q=0.9' --compressed
    • 接口數據處理,返回json格式
      • get
        • 請求添加代碼

        • curl 'http://127.0.0.1:8000/login/?username=1111&mobile=23123&data=32452342' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: zh-CN,zh;q=0.9' --compressed
      • post
        • 請求添加代碼
        • 打開頁面請求後

          curl 'http://127.0.0.1:8000/login/' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36' -H 'Origin: http://127.0.0.1:8000' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3' -H 'Referer: http://127.0.0.1:8000/login/' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: zh-CN,zh;q=0.9' --data 'username=312312&password=231321' --compressed
相關文章
相關標籤/搜索