Python中post与get方式提交数据的代码实例分享


当前第2页 返回上一页

1

2

3

4

5

6

7

8

9

10

11

12

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方式的写法如下:


1

2

3

4

5

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

总结

以上就是Python中post与get方式提交数据的代码实例分享的详细内容,更多文章请关注木庄网络博客!!

返回前面的内容

相关阅读 >>

Python之中的迭代与迭代对象是什么?

Python中的模块string.py

Python中对self的理解

Python中回调的含义详解

数据分析师为什么要学Python

Python中select模块的深度解析

Python print()打印怎么不换行

Python实战爬虫视频教程的资料推荐

Python英语是什么意思

如何用Python爬虫获取那些价值博文

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...