python3 request模塊初使用


 1 import requests
 2 class Interface_Request:
 3 
 4     def __init__(self,url,mobilephone,pwd):
 5         '''login參數初始化'''
 6         self.url = url
 7         self.dict = {'mobilephone':mobilephone,'pwd':pwd}
 8 
 9     def http_request(self,way):
10         '''login接口請求'''
11         if way=='get':
12             return requests.get(self.url,self.dict).headers
13         elif way=='post':
14             while(True):
15                 Question = input('是否使用json傳遞?請輸入y/n')
16                 if Question=='y' or Question=='n':
17                     if Question=='y':
18                         return requests.post(self.url,json=self.dict).headers
19                     elif Question == 'n':
20                         return requests.post(self.url,self.dict).headers
21                 else:
22                     print('請重新輸入!')
23                     continue
24 if __name__ == '__main__':
25     login = Interface_Request('URL地址','手機號','密碼')
26     print('get傳參:',login.http_request('get'))
27     print('post傳參:',login.http_request('post'))

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM