国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python使用post及get方式提交數據的實例

2020-02-16 00:52:40
字體:
來源:轉載
供稿:網友

最近在使用Python的過程中,發現網上很少提到在使用post方式時,怎么傳一個數組作為參數的示例,此處根據自己的實踐經驗,給出相關示例:

單純的post請求:

def http_post():  url = "http://152.1.12.11:8080/web"  postdata = dict(d=2, p=10)  post = []  post.append(postdata)  req = urllib2.Request(url, json.dumps(post)) #需要是json格式的參數  req.add_header('Content-Type', 'application/json') #要非常注意這行代碼的寫法  response = urllib2.urlopen(req)  result = json.loads(response.read())  print result

需要token時寫法如下:

def http_post():  url = "http://152.1.12.11:8080/web"  postdata = dict(d=2, p=10)  post = []  post.append(postdata)  req = urllib2.Request(url, json.dumps(post))  access_token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1bmlxdWVfbmFtZSI6I..........'  req.add_header('Authorization', access_token) #header中添加token  req.add_header('Content-Type', 'application/json') #要非常注意這行代碼的寫法  response = urllib2.urlopen(req)  result = json.loads(response.read())  print result

get方式的寫法如下:

def get_access_token():  local_url = 'http://152.1.1.1:8080/web'  response = urllib2.urlopen(local_url).read()  resp = json.loads(response)  print resp

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對武林站長站的支持。如果你想了解更多相關內容請查看下面相關鏈接

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 玉龙| 辉县市| 德阳市| 合江县| 枣强县| 德兴市| 上林县| 英山县| 远安县| 海口市| 韶关市| 田阳县| 隆子县| 安乡县| 伊宁县| 莎车县| 囊谦县| 定兴县| 盖州市| 凤台县| 高唐县| 海南省| 崇仁县| 霞浦县| 祁门县| 石景山区| 嘉义县| 麻栗坡县| 句容市| 桦南县| 平山县| 万全县| 雅江县| 清镇市| 根河市| 鹤庆县| 西乌珠穆沁旗| 都兰县| 襄樊市| 石渠县| 乌鲁木齐县|